I am creating a custom filter for WooCommerce products. I have the following WP_Query to filter on selected products:
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'pa_size',
'terms' => $sizeFilter,
'field' => 'slug'
),
array(
'taxonomy' => 'product_cat',
'terms' => $catFilter,
'field' => 'slug'
),
array(
'taxonomy' => 'pa_color',
'terms' => $colorFilter,
'field' => 'slug'
)
)
);
I also want to add a meta_query to filter on product price. However, I want to find products with a given price AND the tax_query filter above. Is there a way to do a relation => 'AND'
between the meta_query and tax_query?
'meta_query' => array(
'relation' => 'OR',
array(
'key' => '_price',
'value' => $priceFilter,
'compare' => 'IN'
),
)
When I add the meta_query within the array, no products are returned. I tried separating the two queries into two arrays and then merging the arrays, but it was not a "relation => AND".