恐怕没有什么好办法。。。
One way will be to:
<获取所有找到的帖子,每个帖子都有自己的条款,计算条款但这不是很有效,我不推荐这种方式。
另一方面there is an efficient, 但这不是很好的方法-使用SQL查询:
$query = new WP_Query(array(\'post_type\' => \'foo\', \'numberposts\' => 20));
$ids = wp_list_pluck($query->posts, \'ID\');
$placeholders = array_fill(0, count($ids), \'%d\');
$format = implode(\', \', $placeholders);
$results = $wpdb->get_results( $wpdb->prepare(
" SELECT terms.name, COUNT(tr.object_id) as count FROM {$wpdb->terms} terms " .
" INNER JOIN {$wpdb->term_taxonomy} tt ON (tt.term_id = terms.term_id) " .
" INNER JOIN {$wpdb->term_relationships} tr ON (tr.term_taxonomy_id = tt.term_taxonomy_id) " .
" WHERE tr.object_id IN ({$format}) GROUP BY terms.term_id ",
$ids
) );