我需要所有这两个类别的产品。我正在使用以下查询:
$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有子类别,则查询是相同的,只是没有结果。
谢谢
 
                SO网友:Markus Drubba
                设置include_children 在tax\\u查询中为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_Reference/WP_Query#Taxonomy_Parameters