This is really confusing me.
I've tried numerous things but cannot get appropriate results.
Here's what I currently have for my query:
$args = array(
'post_type' => 'product',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'ring' ),
),
array(
'taxonomy' => 'product_tag',
'field' => 'slug',
'terms' => array( 'black', 'men' ),
),
),
);
$query = new WP_Query( $args );
As you can see I am trying to return products in the product category ring
that contain both the tags black
AND men
...
It appears though the product_tag
terms
array which includes black
and men
, is returning posts that include the tag black
OR the tag men
in the ring
category.
How do I get it so that only products that include BOTH the tags in the query are returned?
Thanks so much
This is really confusing me.
I've tried numerous things but cannot get appropriate results.
Here's what I currently have for my query:
$args = array(
'post_type' => 'product',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'ring' ),
),
array(
'taxonomy' => 'product_tag',
'field' => 'slug',
'terms' => array( 'black', 'men' ),
),
),
);
$query = new WP_Query( $args );
As you can see I am trying to return products in the product category ring
that contain both the tags black
AND men
...
It appears though the product_tag
terms
array which includes black
and men
, is returning posts that include the tag black
OR the tag men
in the ring
category.
How do I get it so that only products that include BOTH the tags in the query are returned?
Thanks so much
Share Improve this question asked May 5, 2020 at 12:25 bbrumanbbruman 4841 gold badge5 silver badges16 bronze badges1 Answer
Reset to default 0Nevermind I (think) I got it...
$args = array(
'post_type' => 'product',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'ring' ),
),
array(
'taxonomy' => 'product_tag',
'field' => 'slug',
'terms' => array( 'black', 'men' ),
'operator' => 'AND'
),
),
);
Missing the 'operator'
=> 'AND'
key value pair