WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does anyone know how I can get a list of posts based on their recent activity? Activity such as a new comment, an edit, a new post, et cetera.

Some Q&A wordpress themes seem to be using this but I have no clue on how to generate such a query myself...

Please, it's very important.

share|improve this question

This needs to be 2 queries, one to get the posts most recently commented like:

$q = "SELECT wp_comments.comment_post_id, wp_posts.* FROM wp_comments LEFT JOIN wp_posts ON wp_comments.comment_post_id = wp_posts.ID ORDER by wp_comments.comment_date DESC";

And one to get the most 10 recent posts by add or edit:

$q = "SELECT * FROM wp_posts WHERE post_type='post' OR post_type='revision' ORDER BY post_date DESC";

But when you retrieve the posts from the latter you will need to check if it is a revision and if so get the parent post, and also depending on the reason for this check the status of the post or the parent post to make sure it is published (status of revisions will be inherit)

share|improve this answer

Your Answer


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.