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

目录

描述

Count how many terms are in Taxonomy.

Default $args is 'hide_empty' which can be 'hide_empty=true' or array('hide_empty' => true).

wp_count_terms() 描述

用法

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

wp_count_terms() 用法

参数

$taxonomy

(string) (必填) Taxonomy name.

默认值: string

$args

(mixed) (可选) Overwrite defaults. See get_terms().

默认值: array/string

wp_count_terms() 参数

返回值

(int

How many terms are in $taxonomy

wp_count_terms() 返回值

历史

添加于 版本: 2.3

wp_count_terms() 历史

源文件

wp_count_terms() 函数的代码位于 wp-includes/taxonomy.php

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * 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);
}

wp_count_terms() 源文件

相关