• 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)
  • Bump.

    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.