WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Need 1 post from each.


    global $post; // required

        $args = array (
            'tax_query' => array (
                'relation' => 'AND',
                array (
                    'taxonomy' =>'category',
                    'field' => 'slug',
                    'terms' => array ('economy','the-constitution','monetary-policy','liberty')
                array (
                    'taxonomy' => 'highlight',
                    'field' => 'slug',
                    'terms' => array ('lead','featured'),
                    'operator' => 'NOT IN' 

        $posts = get_posts($args);

        foreach ($posts as $post) {

            setup_postdata($post); ?>

            <li class="post">
                <?php if(has_post_thumbnail()): ?><div class="imgframe"><?php the_post_thumbnail('PostThumbSideBar'); ?></div><?php else: endif; ?>
                <p class="meta"><?php the_category(' '); ?> <?php the_tags(' '); ?></p>
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>

    <?php } ?>
    <?php wp_reset_query(); // reset the query ?>
share|improve this question
up vote 0 down vote accepted
$categories = array('economy','the-constitution','monetary-policy','liberty');
foreach($categories as $category) {
    $args = array(
        'posts_per_page' => 1,
        'category_name' => $category,
        'tax_query' => array(
                'taxonomy' => 'highlight',
                'field' => 'slug',
                'terms' => array( 'lead','featured' ),
                'operator' => 'NOT IN'
    $wpse42358_query = new WP_Query( $args );
    while( $wpse42358_query->have_posts() ) : $wpse42358_query->the_post();
        // write post stuff here

I opted to use WP_Query because you have more control on taxonomy queries.

share|improve this answer
Nice! 'relation' => 'AND' .. along with 'operator' => 'not in'(being added under terms) sealed the deal. Without those adjustments it wasn't working properly. If you wanna edit your answer to reflect those changes I'll award the answer - Thanks! – Daniel Fris Feb 15 '12 at 17:24
Good call. Actually now that I think about it, you probably do not even need relation because it is only one. – imHavoc Feb 15 '12 at 17:54

Your Answer


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.