If you use WP_Query
's tax_query
, you can set the operator
to NOT IN
and then just list your terms. The best way to do this (IMO) is to generate the tax query separately and dynamically, since all that will be changing in each of the different arguments is the slug/id of the category name. Your code should look something like this:
$tax_query = array();
$tax_query['relation'] = 'OR'; // look for any of the following
$tax_query[] = array(
'taxonomy' => 'your-taxonomy', // exactly what it sounds like
'field' => 'slug or ID', // put either slug or id, depends on what $term is
'terms' => $array_of_terms,
'operator' => 'NOT IN'
);
Note: I wrote this straight into the editor, it's totally untested and is more pseudocode than actual code. You will need to provide your own array for $array_of_terms
, that's simple stuff though.
Once you've got that, you can just set 'tax_query' => $tax_query
as one of your WP_Query
args.