caleb2
1/10/2017 - 10:41 PM

SQL query to count total number of post meta rows per post type

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