Find the latest post for each author and then group the results

x theme

Following is a WordPress database query to fetch the latest post for each author and then group the result. By using this query, you’ll be able to only get a single latest post from each author.

Here is the code for displaying only one latest post from each author:


SELECT
wp_posts.*
FROM wp_posts
WHERE
wp_posts.post_status='publish'
AND wp_posts.post_type='post'
GROUP BY wp_posts.post_author
HAVING wp_posts.post_date = MAX(wp_posts.post_date) // ONLY THE LAST POST FOR EACH AUTHOR
ORDER BY wp_posts.post_date DESC

Leave a Reply

Your email address will not be published. Required fields are marked *