Skip to content

Instantly share code, notes, and snippets.

@dboutote
Created March 13, 2016 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dboutote/09411cd2c0187a341156 to your computer and use it in GitHub Desktop.
Save dboutote/09411cd2c0187a341156 to your computer and use it in GitHub Desktop.
[WordPress] Get recent comments grouped by post
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