Skip to content

Instantly share code, notes, and snippets.

@crstauf
Last active January 10, 2017 22:44
Show Gist options
  • Save crstauf/ee84d7edd713d2a15f8cb9510aaf8b56 to your computer and use it in GitHub Desktop.
Save crstauf/ee84d7edd713d2a15f8cb9510aaf8b56 to your computer and use it in GitHub Desktop.
SQL query to count total number of post meta rows per post type
SELECT
p.`post_type`,
COUNT( pm.`post_id` ) as postmeta_count
FROM `wp_posts` as p
JOIN `wp_postmeta` as pm
ON (p.`ID` = pm.`post_id`)
GROUP BY p.`post_type`
ORDER BY
postmeta_count DESC,
p.`post_type` ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment