正如@shanebp所建议的,您可以使用wp_count_terms()
像这样:
$numTerms = wp_count_terms( \'service-category\', array(
\'hide_empty\'=> false,
\'parent\' => 0
) );
以上将列出所有顶级父术语,无论是否为空。此函数使用
get_terms()
可以在链接中找到的函数参数或以下参数:
$args = array(
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'hide_empty\' => true,
\'exclude\' => array(),
\'exclude_tree\' => array(),
\'include\' => array(),
\'number\' => \'\',
\'fields\' => \'all\',
\'slug\' => \'\',
\'parent\' => \'\',
\'hierarchical\' => true,
\'child_of\' => 0,
\'get\' => \'\',
\'name__like\' => \'\',
\'description__like\' => \'\',
\'pad_counts\' => false,
\'offset\' => \'\',
\'search\' => \'\',
\'cache_domain\' => \'core\'
);