Display only the latest post from multiple categories

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);
endforeach;

if($posts): ?>
<ul>
<?php foreach( $posts as $post ) :  setup_postdata($post); ?>
   <li><a href="https://wordpress.stackexchange.com/questions/26227/<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>

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

Leave a Comment