获取WooCommerce中没有特定分类标准的产品列表

我试图找出哪些产品缺少具有数以万计产品的网站上的供应商的问题。获取WooCommerce中没有特定分类标准的产品列表

我需要一个MySQL查询来确定哪些产品通过phpmyadmin缺少分类“供应商”。

到目前为止,我已经在一起从不同的答案拼凑这样的:

SELECT * 

FROM wp_posts wp

INNER JOIN wp_postmeta wm ON (wm.`post_id` = wp.`ID`)

INNER JOIN wp_term_relationships wtr ON (wp.`ID` = wtr.`object_id`)

INNER JOIN wp_term_taxonomy wtt ON (wtr.`term_taxonomy_id` = wtt.`term_taxonomy_id`)

INNER JOIN wp_terms wt ON (wt.`term_id` = wtt.`term_id`)

AND wtt.`taxonomy` = 'suppliers'

WHERE post_type = 'product'

GROUP BY wp.ID

我试过很多东西并不能得到它的工作。

回答:

问题是与您查询的是,你不能排除有suppliers是该产品有一些其他属性的产品,所以你可以使用NOT EXISTNOT IN,我已经写了使用NOT EXIST查询。

SELECT * 

FROM wp_posts wp

INNER JOIN wp_postmeta wm ON wm.`post_id` = wp.`ID`

INNER JOIN wp_term_relationships wtr ON (wp.`ID` = wtr.`object_id`)

INNER JOIN wp_term_taxonomy wtt ON wtr.`term_taxonomy_id` = wtt.`term_taxonomy_id`

INNER JOIN wp_terms wt ON wt.`term_id` = wtt.`term_id`

WHERE post_type = 'product'

AND NOT EXISTS

(SELECT `object_id`

FROM `wp_term_relationships` AS wtr_inner

WHERE `term_taxonomy_id` IN

(SELECT term_taxonomy_id

FROM `wp_term_taxonomy`

WHERE `taxonomy` = 'suppliers')

AND wtr.object_id = wtr_inner.object_id)

GROUP BY wp.ID

另一个版本,这将是一个快一点,如果你知道所有的suppliersterm_taxonomy_id所以,你可以修改上面的查询作为

SELECT * 

FROM wp_posts wp

INNER JOIN wp_postmeta wm ON wm.`post_id` = wp.`ID`

INNER JOIN wp_term_relationships wtr ON (wp.`ID` = wtr.`object_id`)

INNER JOIN wp_term_taxonomy wtt ON wtr.`term_taxonomy_id` = wtt.`term_taxonomy_id`

INNER JOIN wp_terms wt ON wt.`term_id` = wtt.`term_id`

WHERE post_type = 'product'

AND NOT EXISTS

(SELECT `object_id`

FROM `wp_term_relationships` AS wtr_inner

WHERE `term_taxonomy_id` IN (27,28,29) -- replace it will all suppliers term_taxonomy_id

AND wtr.object_id = wtr_inner.object_id)

GROUP BY wp.ID

希望这有助于!

以上是 获取WooCommerce中没有特定分类标准的产品列表 的全部内容, 来源链接: utcz.com/qa/261376.html

回到顶部