You can setup a tax_query
with the NOT IN
operator.
WP_Query( array(
'post_type' => 'product',
'posts_per_page' => 500,
'tax_query' => array(
'relation' => 'AND'
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'cars' ),
),
array(
'taxonomy' => 'product_tag',
'field' => 'slug',
'terms' => array( 'whatever_tag_i_dont_need' ),
'operator' => 'NOT IN',
),
),
) )
The above will request all posts in assigned to term cars
that don’t have any tags with the slug whatever_tag_i_dont_need
. There’s other comparison operator too. For more information please reference the docs below:
https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters