WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 have a jQuery slider at the top of my index.php, which works fine. The only problem is that I would like to use query_posts to only display the latest post from five different categories, and always show one from each.

So when a new post is created in, lets say the category interview, this will be displayed. But the interview post which was posted one day earlier will then not be displayed, but the latest post from the four other categories are still there.

I think this is a bit complicated, no?

share|improve this question
Don't use query_posts() for a secondary loop, such as a posts slider, especially on index.php. Using query_posts() is intended only for the primary Loop. Use get_posts() or WP_Query() instead, for secondary loops. – Chip Bennett Oct 27 '11 at 15:27
Thanks for the comment Chip! What can this cause? Extra load on the database? – Mats Nov 10 '11 at 20:24

i think you'd have to use get_posts 5 different times. what about this:

global $post;
$posts = array();

//categories you want to pull latest posts from;
$cats = (1,2,3,4,5);

foreach($cats as $cat):
$args = array( 'numberposts' => 1, 'category' => $cat ); 
$posts[] = get_posts($args);

if($posts): ?>
<?php foreach( $posts as $post ) :  setup_postdata($post); ?>
   <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
<?php endif; ?>

i totally didn't test this, but I think it might work

share|improve this answer
Hmm, yeah, maybe. I'll have to play around a bit. Thanks for the help. – Mats Sep 4 '11 at 15:36

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.