wp_count_terms()
wp_count_terms( string $taxonomy, array|string $args = …
wp_count_terms( string $taxonomy, array|string $args = array() )
计算分类学中有多少术语。
Count how many terms are in Taxonomy.
目录锚点:#说明#参数#源码
说明(Description)
默认的$args是’hideuempty’,可以是’hideuempty=true’或array(’hide’u empty’=>true)。
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $taxonomy | (string) | 分类名称。 |
| $args | (array | string) | 传递给get_terms()的参数数组。 |
源码(Source)
/**
* Count how many terms are in Taxonomy.
*
* Default $args is 'hide_empty' which can be 'hide_empty=true' or array('hide_empty' => true).
*
* @todo Document $args as a hash notation.
*
* @since 2.3.0
*
* @param string $taxonomy Taxonomy name
* @param array|string $args Overwrite defaults. See get_terms()
* @return array|int|WP_Error How many terms are in $taxonomy. WP_Error if $taxonomy does not exist.
*/
function wp_count_terms( $taxonomy, $args = array() ) {
$defaults = array('hide_empty' => false);
$args = wp_parse_args($args, $defaults);
// backwards compatibility
if ( isset($args['ignore_empty']) ) {
$args['hide_empty'] = $args['ignore_empty'];
unset($args['ignore_empty']);
}
$args['fields'] = 'count';
return get_terms($taxonomy, $args);
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.3.0 | wp-includes/taxonomy.php | 12 | 17 |
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。


还没有任何评论,赶紧来占个楼吧!