tags:

views:

26

answers:

1

What's the query to list wordpress posts by most recent, with posts most recently commented on going to the top of the order? (Standard "message board" style)

This post looked promising:

http://stackoverflow.com/questions/698438/ordering-wordpress-posts-by-most-recent-comment

But the query is clearly wrong.

Can anyone help?

A: 

How about;

SELECT * FROM $wpdb->posts LEFT JOIN $wpdb->comments
ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID
GROUP BY $wpdb->posts.ID
ORDER BY $wpdb->comments.comment_date DESC
LIMIT X,Y

This would get posts, limited in the range X,Y, with posts that have comments, and those with the most recent comments, listed first.

UPDATED

Additonal ORDER BY clause;

ORDER BY $wpdb->comments.comment_date DESC, $wpdb->post_date DESC 
TheDeadMedic
Interesting but what I'm really looking for is "message board style" - a chronological list of posts, and those with the most recent comments at the top.
Hardseat
That query should do it, though I forgot to add the secondary ORDER BY clause (check revision).
TheDeadMedic