我需要所有的产品,其中有两个类别。我正在使用以下查询:
$args = array(
'post_type' => array('product', 'product_variation'),
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'shop', 'cat1' ),
'operator' => 'AND',
)
)
);如果cat1类别没有像cat1-1、cat1-2等任何子类别,那么它是正确工作的。但是当我在cat1后端创建子类别时,结果将为零。
如果cat1有子类别,查询是相同的,只是没有结果。
谢谢
发布于 2016-10-17 20:33:47
将include_children设置为tax_query中的false。
$args = array(
'post_type' => array( 'product', 'product_variation' ),
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'shop', 'cat1' ),
'include_children' => false,
'operator' => 'AND',
)
));
请参阅https://codex.wordpress.org/Class_参考/可湿性粉剂_Query#Taxonomy_参数
https://wordpress.stackexchange.com/questions/243030
复制相似问题