Title: wp_query exclude taxonomy
Last modified: August 20, 2016

---

# wp_query exclude taxonomy

 *  [hp3](https://wordpress.org/support/users/hp3/)
 * (@hp3)
 * [15 years ago](https://wordpress.org/support/topic/wp_query-exclude-taxonomy/)
 * I want to show posts from a custom post type that have a term from one taxonomy
   but exclude posts that have a term from another taxonomy.
 * show all posts from a given post type that have a term named ‘A’ with a value
   of ‘foo’ from a taxonomy named ‘taxonomy 1’ but exclude any posts which also 
   have a term named ‘B’ with a value of ‘bar’ from a taxonomy named ‘taxonomy 2’
 * can I perform this type of query by passing an array to wp_query or do I have
   to write a SELECT statement and query the database directly?
 * The taxonomy query examples on the wp_query use ‘relation’ such as “AND” and ‘
   operator’ such as “NOT IN” to refine a query but it is not clear to me how to
   use these in an array to build my query for wp_query.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [web559](https://wordpress.org/support/users/web559/)
 * (@web559)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/wp_query-exclude-taxonomy/#post-2122112)
 * Bump.
 *  [Tim Bowen](https://wordpress.org/support/users/creativeslice/)
 * (@creativeslice)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/wp_query-exclude-taxonomy/#post-2122144)
 * Here’s how to exclude a custom taxonomy but show the rest of the posts from this“
   news” custom post type:
 *     ```
       $happening = new WP_Query(
           array(
             'post_type' 	=> 'news',        // only query News post type
             'order'		=> 'DESC',
             'tax_query'	=> array(
               array(
                   'taxonomy'  => 'news-cat',
                   'field'     => 'slug',
                   'terms'     => 'media', // exclude media posts in the news-cat custom taxonomy
                   'operator'  => 'NOT IN')
                   ),
              )
           );
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘wp_query exclude taxonomy’ is closed to new replies.

## Tags

 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [Tim Bowen](https://wordpress.org/support/users/creativeslice/)
 * Last activity: [14 years, 8 months ago](https://wordpress.org/support/topic/wp_query-exclude-taxonomy/#post-2122144)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
