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.

What I'm looking to do it get the 16 latest posts from 16 different authors. In other words there would be the 16 latest posts, but no one single author would have more that 1 post on the page.

The way I've thought about doing it, is looping through all the authors, removing the duplicates, then limited that to 16 and use that to generate the posts in a for each loop, but I'd imagine that would be heavy on the server.

Any suggestions?

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

Use a custom SQL query to grab the latest 16 post IDs with unique authors;

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

Then start up a new query with the post__in argument;

$recent_posts = new WP_Query( array( 'post__in' => $post_IDs, 'post_type' => 'product' ) );
share|improve this answer
    
I think its almost there, the results also need to be from a custom post type "product," but I'm having trouble when I edited the query. 'code' $post_IDs = $wpdb->get_col( "SELECT ID FROM $wpdb->posts GROUP BY post_author WHERE post_type = 'product' ORDER BY post_date DESC LIMIT 16" ); 'code' thoughts? –  pete_schuster Jun 13 '11 at 17:24
    
UPDATE: Moved the WHERE before the GROUP and its working in PHPMyAdmin, but not on the site: $post_IDs = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type = 'product' GROUP BY post_author ORDER BY post_date DESC LIMIT 14" ); $args = array( 'post__in' => $post_IDs ); –  pete_schuster Jun 13 '11 at 17:47
    
Update: Got it I just could use the post__in, I had to use a for each loop for each of the IDs. thanks. –  pete_schuster Jun 13 '11 at 18:11
    
@philmadelphia I wouldn't advise querying in a loop - that'll be 40+ database queries! You also need to add the post_type arg in your query call too - see revised answer. –  TheDeadMedic Jun 13 '11 at 18:35
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.