Is there a simple or easy way to exclude all posts from a custom taxonomy in the loop? I’ve been looking high and low, and neither SE, SO or Google seem to have a straight answer.
I know it can be done via a WPDB query, but that just seems like massive rope to jump for something that should be fairly simple.
You would want to use the NOT EXISTS
operator along with passing the taxonomy slug, which tells the query not to include any of a chosen category from your custom taxonomy inside the loop.
To exclude all posts that are in the taxonomy “fruit” (regardless of fruit kind), here is the snippet:
$args = array(
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'fruit',
'operator' => 'NOT EXISTS'
)
)
);
$query = new WP_Query( $args );