WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've searched high and low, but haven't found the exact code to do this.

I want to show all posts of a that don't have a custom taxonomy assigned.

So something like, pull all posts that have one of the custom taxonomy, then show everything but those posts.

share|improve this question

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.