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.

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

1 Answer 1

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

 
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.