获取所有同时具有产品类别的产品

I need all products which have both categories. I am using a query below:

$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',
                                )
                            )
                        );

It's working correctly if cat1 category does not have any subcategory like cat1-1,cat1-2 etc. But when i made subcategory in backend of cat1 than result will give zero.

Query is same just no result if cat1 have subcategory.

Thanks

Add include children in your arguments.

Make sure your products have both categories.

In case you want to filter by multiple categories operator could be 'IN' instead of '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',
        )
    )
);