I need to retrieve all simple products and product variations that:
- Have
post_statusequal topublish; - Simple products and product variations belong to a specific product category (in my case mobile);
But excluding the variable products.
So far I have tried this code but it doesn't work:
$arg_product_filter = array(
'nopaging' => true,
'post_status' => array( 'publish' ),
'posts_per_page' => -1,
'post_type' => array( 'product', 'product_variation' ),
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_type',
'field' => 'slug',
'terms' => array( 'simple', 'variation' ),
),
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'mobile',
)
),
);
$the_query = new WP_Query( $arg_product_filter );
This query returned only simple products and if I change the relation to 'OR' it returns variable products as well. What I am doing wrong?