计算分类法中有多少项。
原型
wp_count_terms( string $taxonomy, array|string $args = array() )
描述
默认$ args是’hide_empty’,可以是’hide_empty = true’或array(‘hide_empty’=> true)。
参数
$taxonomy
(string)
(Required)
分类名称。
$args
(array|string)
(Optional)
传递给get_terms()的参数数组。
返回值
(array|int|WP_Error)
该分类中的术语数量或
源文件
路径:wp-includes/taxonomy.php
<?php
...
function wp_count_terms( $taxonomy, $args = array() ) {
$defaults = array('hide_empty' => false);
$args = wp_parse_args($args, $defaults);
// backward compatibility
if ( isset($args['ignore_empty']) ) {
$args['hide_empty'] = $args['ignore_empty'];
unset($args['ignore_empty']);
}
$args['fields'] = 'count';
return get_terms($taxonomy, $args);
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_count_terms/