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 am using pre_get_posts for a custom taxonomy archive display. Now I added a post type 'photo' sharing the same taxonomy with default post type. How can I exclude 'photo' posts being fetched by the taxonomy archive loop by updating my existing function?

function my_breakfast_query ( $query ) {
// not an admin page and is the main query
if (!is_admin() && $query->is_main_query()){
if (is_tax( 'food', 'breakfast' )){
  $tax_query = array(
    'relation' => 'OR',
    array(
      'taxonomy' => 'category',
         'field' => 'id',
         'terms' => array( 366 )
    ),
    array(
        'taxonomy' => 'food',
         'field' => 'id',
         'terms' => array( 364 )
    )
  );
  $query->set('tax_query', $tax_query);
 }
 }
}
add_action( 'pre_get_posts', 'my_breakfast_query' );
share|improve this question

1 Answer 1

up vote 1 down vote accepted

I found a solution to this myself. It returns the default post type posts instead of excluding the custom post type which is fine for my needs.

function my_breakfast_query ( $query ) {
// not an admin page and is the main query
if (!is_admin() && $query->is_main_query()){
if (is_tax( 'food', 'breakfast' )){
  $tax_query = array(
    'relation' => 'OR',
     array(
        'taxonomy' => 'category',
        'field' => 'id',
        'terms' => array( 366 )
     ),
     array(
        'taxonomy' => 'food',
        'field' => 'id',
        'terms' => array( 364 )
     )
  );
  $query->set('post_type','post'); // Added this line to get a working solution
  $query->set('tax_query', $tax_query);
 }
 return $query; // Added this line to get a working solution
 }
}
add_action( 'pre_get_posts', 'my_breakfast_query' );
share|improve this answer
    
Please provide the code in your answer... –  kaiser Jul 7 '13 at 11:43

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.