$sql = "SELECT post_id, COUNT(meta_key) TotalMetaKey FROM `wp_postmeta` GROUP BY post_id"; echo $sql;