上面另外两个答案的一个稍微快一点的版本:计算MySQL查询中的帖子数。
$state_query = $wpdb->get_results("
SELECT meta_value AS state, COUNT(post_id) AS count
FROM {$wpdb->postmeta} WHERE meta_key = \'state\'
GROUP BY state ORDER BY state ASC");
if ($state_query) {
echo \'<ul>\';
foreach ($state_query as $st)
echo \'<li>\' . $st->state . \' - \' . $st->count . \' posts\' . \'</li>\';
echo \'</ul>\';
}