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.

Need 1 post from each.

<?php 

    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>
            </li>

    <?php } ?>
    <?php wp_reset_query(); // reset the query ?>
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted
<?php
$categories = array('economy','the-constitution','monetary-policy','liberty');
foreach($categories as $category) {
    $args = array(
        'posts_per_page' => 1,
        'category_name' => $category,
        'tax_query' => array(
            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
    wp_reset_postdata();
}
?>

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
add comment

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.