Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

<?php

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

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

<?php endwhile;
// Reset Query
wp_reset_query();
?>

How can I add that filter?

share|improve this question
    
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

1 Answer 1

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(
     array(
       'taxonomy' => 'content',
       'field'    => 'slug',
       'terms'    => 'indy',
       'operator' => 'NOT IN' 
     )
   )
);

$myquery = new WP_Query( $args );
while( $myquery->have_posts() ):
  $myquery->the_post();
  # do your stuff here
endwhile;
share|improve this answer
    
Worked perfectly, thanks. –  Chozen Feb 27 '13 at 1:53

Your Answer

 
discard

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.