Showing Recent authors – WordPress

While helping my friend on community blog related to travel, i faced this requirement. He owns a website/blog where people share their travel experiences. We wanted to show 5 authors who contributed last i.e. people who wrote posts very recently. We googled and did not find any thing which can address our requirement exactly. During our search we were getting results related to recenlty registered users with the blog.

I finally decided to do it by direct query to the database. Here is the query which gives the correct result for people who contributed very recently on blog.

Use following code to use above query in wordpress page:

<?php $fiverecentAuthors = $wpdb->get_results("SELECT post_author, max(post_date) as postdate FROM wp_posts WHERE post_type = 'post' AND post_status='publish' GROUP BY post_author ORDER BY postdate DESC LIMIT 5");

	foreach ($fiverecentAuthors as $recentAuthor) {
		$userId = $recentAuthor->post_author;
	}
?>

You can direclty get the user’s data using get_userdata() function supported by wordpress and use it for displaying details about selected authors.

<?php
    $user = get_userdata($userId);
?>

Hope it can be used by some people looking for similar requirements.

Most Commented Posts

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)