让MySQL来完成这项工作:
global $wpdb;
$metakey = \'YOUR_METAKEY_GOES_HERE\';
$results = $wpdb->get_results(
$wpdb->prepare(
"SELECT meta_value, COUNT(*) AS counter from {$wpdb->postmeta} WHERE meta_key = %s GROUP BY meta_value ORDER BY counter DESC", $metakey, ARRAY_N )
);
);
$resuls
是一个具有有序结果的数组。