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.

I'm attempting to display the latest 5 post excerpts from 5 different authors in my blog sidebar. Below is the code I'm using which I tweaked from this thread: Find most recent authors

So far, I've gotten it to work however rather than display each individual author's most recent post, it's showing the author's earliest post. Any ideas on what I'm doing wrong? I've been struggling w/ this for a few days so appreciate any direction you can give. I'm a newbie to PHP but can understand enough to tweak code. Thanks!! You can see it working on my site: wearestd.com

<?php
global $wpdb;

$post_IDs = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY post_author ORDER BY post_date DESC LIMIT 5" );

$my_query = new WP_Query( array( 'post__in' => $post_IDs) );

if( $my_query->have_posts() ) {
  while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php userphoto_the_author_thumbnail() ?>
<div id="author_excerpt"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><h4><?php the_title(); ?></h4><br />
<?php the_advanced_excerpt('length=50'); ?></a>
<?
endwhile;
}
?>
share|improve this question
    
try changing DESC to ASC in the sql query. –  Bainternet Jul 6 '11 at 7:07
    
I tried that, same results –  Adrian Jul 6 '11 at 7:22
add comment

1 Answer

Think I've figured it out. Here's the code I used courtesy of this thread on the WP Support Forum. Just replace ()<?php the_author_posts_link(); ?>() with whatever excerpt code you want to use. And Voila!

<?php
//list 5 latest authors
$authors =  array();
$count = 0;
$args=array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts() && $count < 5) : $my_query->the_post();
$author_id=$my_query->post->post_author;
if (!in_array($author_id,$authors)) { ?>
<?php the_author_posts_link(); ?>
<?php $count++;
$authors[]=$author_id;
}
endwhile;
}
wp_reset_query();  // Restore global post data stomped by the_post().
?>
share|improve this answer
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.