Created
March 13, 2016 22:24
-
-
Save dboutote/09411cd2c0187a341156 to your computer and use it in GitHub Desktop.
[WordPress] Get recent comments grouped by post
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.* | |
FROM `dbdb`.`wp_comments` c | |
LEFT JOIN `dbdb`.`wp_comments` c2 ON c.comment_post_ID = c2.comment_post_ID AND c.comment_date_gmt < c2.comment_date_gmt | |
JOIN `dbdb`.`wp_posts` ON `dbdb`.`wp_posts`.ID = c.comment_post_ID | |
WHERE c2.comment_date_gmt is NULL | |
AND ( c.comment_approved = '1' ) | |
AND c.comment_type NOT IN ('pingback', 'trackback') | |
AND `dbdb`.`wp_posts`.post_status IN ('publish') | |
AND `dbdb`.`wp_posts`.post_type IN ('post') | |
ORDER BY c.comment_date_gmt DESC | |
LIMIT 10; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment