本文介绍了SQL查询以检查WooCommerce中的product_type的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to filter products in WooCommerce by Simple or Variable Product through MySQL; but I could not find as how the WooCommerce stores the data and distinguishes between them in database.

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

I want an MySQL query to list all the Simple and Variable Product; I don't need any PHP code.

类似的东西:

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

推荐答案

MySQL查询以列出所有简单产品:

MySQL query to list all Simple Products:

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,即可获取所有可变产品;

Just replace simple from AND terms.slug = 'simple' line with variable to get all Variable Products;

我已经测试了此SQL查询,并且显示了正确的结果.

希望这会有所帮助!

这篇关于SQL查询以检查WooCommerce中的product_type的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 23:50