I want to display the latest post from a "featured" category (id=1) that may also be in either X category, Y category, or Z category (id=2,3,4 respectively). Note, there are other posts in categories (A,B) that may also be listed under "featured" but I want to limit my results to the XYZ set.

Is there any special loop I can use to achieve this, or do I need to run a SQL query?

Also important to know that these are all top-level categories, so no child or parent cats to look through.

2 Answers 2


Maybe this could help and should return any post either in 2, 3 or 4 category AND in categoery 1 :

query_posts( array( 'cat' => array(2,3,4), 'category__and' => 1, 'posts_per_page' => 1, 'orderby' => 'title', 'order' => 'DESC' ) );

(from codex http://codex.wordpress.org/Function_Reference/query_posts)

Not quite sure, haven't tested it.


how about?

$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();

if ( have_posts() ) while ( have_posts() ) : the_post();
while ($wp_query->have_posts()) : $wp_query->the_post();
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  <div class="entry-content">
    <span class="blog-date"><?php the_time(' M  jS, Y') ?></span>
      <h2 class="blog-post-title">
        <?php the_title(); ?>
      <?php the_content(); ?>
  </div><!-- .entry-content -->
</div><!-- #post-## -->
<?php endwhile; ?>
 $wp_query = null; 
 $wp_query = $temp; 

really just a custom query, which you can still filter to show number of posts etc..

  • This does not limit posts the way I need. In your code, posts that haven't been put in Featured but are in X,Y,or Z can still appear. I need to limit posts from those latter categories to only display IF they are also in Featured.
    – f8xmulder
    Sep 20, 2011 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.