1

I'm trying to display recent posts from regular posts section and custom post types, excluding one custom taxonomy term from each custom post type. But the recent posts section doesn't show anything.

   <?php 
    // the query
    $the_query = new WP_Query(
     array(
    'post_type' => array( 'post', 'miss_behave', 'emily_davies','gemma_patel','poppy_smythe' ),
    'category__not_in' => 4,
    'tax_query'          => array(
    'taxonomy' => array('miss_behave_category','emily_category','gemma_category','poppy_category'),
    'terms' => array(141,142,143,144),      
    'field' => 'id',
    'operator' => 'NOT IN' 
        )
        )
    );?>
1

Your tax_query is incorrect. taxonomy does not take an array.

taxonomy (string) - Taxonomy.

http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

You will need to rewrite your arguments to be more like the following from the Codex:

$args = array(
    'post_type' => 'post',
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'movie_genre',
            'field' => 'slug',
            'terms' => array( 'action', 'comedy' )
        ),
        array(
            'taxonomy' => 'actor',
            'field' => 'id',
            'terms' => array( 103, 115, 206 ),
            'operator' => 'NOT IN'
        )
    )
);
$query = new WP_Query( $args );

You can automate that a bit:

$taxonomies = array('miss_behave_category','emily_category','gemma_category','poppy_category');

$args = array(
  'post_type' => array( 'post', 'miss_behave', 'emily_davies','gemma_patel','poppy_smythe' ),
  'category__not_in' => 4
);

$args['tax_query']['relation'] = 'OR';
foreach ($taxonomies as $tax) {
  $args['tax_query'][] = array(
    'taxonomy' => $tax,
    'terms' => array(141,142,143,144),      
    'field' => 'id',
    'operator' => 'NOT IN' 
  );
}
// var_dump($args);

$the_query = new WP_Query($args);

However, "categories" are a taxonomony so you may as well include them in with the rest of the taxonomies, and all those NOT INs are not likely to be very efficient. I would carefully consider where those need to be included.

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.