【问题标题】:SQL query to check product_type in WooCommerce在 WooCommerce 中检查 product_type 的 SQL 查询
【发布时间】:2017-05-06 07:55:50
【问题描述】:

我想通过 MySQL 按简单或可变产品过滤 WooCommerce 中的产品;但我找不到 WooCommerce 如何在数据库中存储数据并区分它们。

我想要一个 MySQL 查询来列出所有简单和可变产品;我不需要任何 PHP 代码。

类似:

SELECT * FROM wp_posts WHERE post_type = 'product' AND product_type = 'simple';

【问题讨论】:

    标签: mysql wordpress woocommerce


    【解决方案1】:

    MySQL 查询列出所有简单产品

    SELECT
        posts.ID,
        posts.post_title,
        posts.post_author,
        posts.post_date,
        posts.post_date_gmt,
        posts.post_content,
        posts.post_excerpt,
        posts.post_status,
        posts.comment_status,
        posts.ping_status,
        posts.post_password,
        posts.post_name,
        posts.to_ping,
        posts.pinged,
        posts.post_modified,
        posts.post_modified_gmt,
        posts.post_content_filtered,
        posts.post_parent,
        posts.guid,
        posts.menu_order,
        posts.post_type,
        posts.post_mime_type,
        posts.comment_count
    FROM
        wp_posts AS posts
    INNER JOIN wp_term_relationships AS term_relationships ON posts.ID = term_relationships.object_id
    INNER JOIN wp_term_taxonomy AS term_taxonomy ON term_relationships.term_taxonomy_id = term_taxonomy.term_taxonomy_id
    INNER JOIN wp_terms AS terms ON term_taxonomy.term_id = terms.term_id
    WHERE
        term_taxonomy.taxonomy = 'product_type'
    AND terms.slug = 'simple'
    AND posts.post_type = 'product';
    

    只需将AND terms.slug = 'simple' 行中的simple 替换为variable 即可获得所有变量产品

    我已经测试了这个 SQL 查询,它显示了正确的结果。

    希望这会有所帮助!

    【讨论】:

    • 这正是我想要的。非常感谢。
    • @user1375291:如果这对您有帮助,请接受我的回答,我点击右勾号,然后点击向上箭头进行投票。
    • 超级有帮助 - TY .. @user1375291 你应该投票
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-17
    • 1970-01-01
    相关资源
    最近更新 更多