Last active
March 13, 2016 20:02
-
-
Save dboutote/7580bc9e89d29495ddc3 to your computer and use it in GitHub Desktop.
[WordPress] Group Recent Comments by post ID, sort by comment date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT c.comment_ID | |
FROM wp_comments c | |
JOIN | |
( SELECT wp_comments.comment_post_ID, max(wp_comments.comment_date_gmt) maxDate | |
FROM wp_comments | |
GROUP BY wp_comments.comment_post_ID | |
) c2 | |
ON c.comment_date_gmt = c2.maxDate AND c.comment_post_ID = c2.comment_post_ID | |
JOIN wp_posts | |
ON wp_posts.ID = c.comment_post_ID | |
WHERE ( comment_approved = '1' ) | |
AND comment_type NOT IN ('pingback', 'trackback') | |
AND wp_posts.post_status IN ('publish') | |
AND wp_posts.post_type IN ('post') | |
ORDER BY c.comment_date_gmt DESC | |
LIMIT 5; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment