I have a WordPress site with 28 users and would like to get the latest post from each user (just one post per user). I’ve tried with a custom sql using both DISTINCT and GROUP BY, but with no success.
This is the closest I have come. It fetches unique posts, but the oldest post instead of the newest.
function last_post_per_user() {
global $wpdb;
return $wpdb->get_results('SELECT ID FROM '.$wpdb->posts.' WHERE post_status='publish' AND post_type='post' AND post_author!='1' GROUP BY post_author');
}
$posts = last_post_per_user();
foreach ($posts as $post) {
$post_id[] = $post->ID;
}
query_posts( array(
'post_type' => 'post',
'posts_per_page' => 10,
'post__in' => $post_id
) );
Does anyone have any suggestions on how to solve this?
(Have actually tried solving this the whole f*cking day)
Try replacing this:
with this:
It will show the newest posts.