Query the same Taxonomy with different operators
-
Hi,
I want to run a query with tax_query in which one term needs to be present and the other should not be present. Is this the correct way:
$args = [ 'post_type' => $list_post_type, 'numberposts' => $no_of_posts, 'fields' => 'ids', 'meta_key' => $list_meta_key, 'orderby' => 'meta_value_num', 'order' => 'DESC', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'genre', 'field' => 'slug', 'terms' => 'action', 'operator' => 'IN', ), array( 'taxonomy' => 'genre', 'field' => 'slug', 'terms' => 'comedy', 'operator' => 'NOT IN', ), ), ];
I want to output Action Movies which should not have Comedy as a genre.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Query the same Taxonomy with different operators’ is closed to new replies.