获取同时包含产品类别

时间:2016-10-17 18:33:17

标签: php wordpress woocommerce

我需要所有具有两种类别的产品。我正在使用以下查询:

$args = array(
                            'post_type' => array('product', 'product_variation'),
                            'paged' => $paged,
                            'tax_query' => array(
                                array(
                                    'taxonomy' => 'product_cat',
                                    'field' => 'slug',
                                    'terms'    => array( 'shop', 'cat1' ),
                                    'operator' => 'AND',
                                )
                            )
                        );

如果cat1类别没有cat1-1,cat1-2等任何子类别,它正常工作。但是当我在cat1的后端创建子类别时,结果将为零。

如果cat1具有子类别,则查询相同,结果不相同。

由于

1 个答案:

答案 0 :(得分:0)

在参数中添加包含子项。

确保您的产品同时具有两种类别。

如果您想按多个类别进行过滤,则运营商可能会在' IN'而不是' AND'。

$args = array(
'post_type' => array('product', 'product_variation'),
'paged' => $paged,
'tax_query' => array(
        array(
            'taxonomy' => 'product_cat',
            'include_children' => true,
            'field' => 'slug',
            'terms'    => array( 'shop', 'cat1' ),
            'operator' => 'AND',
        )
    )
);
相关问题