WordPress函数wp_count_terms()获取所有的分类信息(可加筛选条件)

描述:

获取所有的分类信息(可加筛选条件)

用法:

<?php wp_count_terms( $taxonomy, $args ); ?>

参数:

$taxonomy

(string) (必填) 分类法名称

默认值: string

$args

(mixed) (可选) 覆盖默认值

默认值: array/string

源文件:

/**
 * 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);
}