I'm querying multiple custom posts types and I'd like to filter certain posts that are tagged with a specific taxonomy term.

The taxonomy is "content" and the term is "indy"

I'm using the the code below.


// The Query
query_posts( array('post_type' => 'post', 'videos', 'music') );

// The Loop
while ( have_posts() ) : the_post(); ?>

<?php endwhile;
// Reset Query

How can I add that filter?

  • is this the main query, or an additional query? what page is this query on? if this is the main query, have a look at pre_get_posts. also see taxonomy and post type parameters for WP_Query. – Milo Feb 26 '13 at 1:46

You should have a look at the arguments of WP_Query. The following arguments should be what you need. Note that tax_query takes an array of arrays.

$args = array(
  'post_type' => array( 'post', 'videos', 'music' ),
  'tax_query' => array(
       'taxonomy' => 'content',
       'field'    => 'slug',
       'terms'    => 'indy',
       'operator' => 'NOT IN' 

$myquery = new WP_Query( $args );
while( $myquery->have_posts() ):
  # do your stuff here
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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