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

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.

share|improve this question

migrated from stackoverflow.com Sep 20 '11 at 12:54

This question came from our site for professional and enthusiast programmers.

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.

share|improve this answer

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..

share|improve this answer
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 '11 at 16:18

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.