开发者

Ordering Wordpress posts by most recently commented on

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:

Ordering Wordpress post开发者_高级运维s by most recent comment

But the query is clearly wrong.

Can anyone help?


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 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜