此查询将在一个查询中获取所有国家/地区和计数:
global $wpdb;
$countries_count = $wpdb->get_results( "
SELECT meta_value AS country, COUNT(post_id) AS count
FROM {$wpdb->postmeta}
WHERE meta_key = \'tgt_job_country\'
GROUP BY country ORDER BY country" );
foreach ($countries_count as $country)
echo "<li><a href=\'http://dsdjjhfgd.net/s=jobseeker&usertype=jobseeker&country=".$country->country."&search=Search\'>".$country->country."(".$country->count.")</a></li>";
除非您需要首先获取国家/地区列表,否则这只会使用数据库中的meta\\u键提取每个值。。。