Skip to content

Instantly share code, notes, and snippets.

@adamcrampton
Created February 6, 2019 00:24
Show Gist options
  • Save adamcrampton/4f3184c1346917cd6f6fac566e099b85 to your computer and use it in GitHub Desktop.
Save adamcrampton/4f3184c1346917cd6f6fac566e099b85 to your computer and use it in GitHub Desktop.
Count all posts in WordPress database by tag or category, and output daily totals
SELECT p.post_date, COUNT(*) FROM wp_posts p
JOIN wp_term_relationships tr
ON p.ID = tr.object_id
WHERE tr.term_taxonomy_id = 15996
AND p.post_status = "publish"
AND p.post_type = "post"
AND p.post_date > "2017-02-06"
GROUP BY YEAR(p.post_date), MONTH(p.post_date), DAY(p.post_date)
ORDER BY p.post_date ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment