wp_count_terms( array|string $args = array(), array|string $deprecated = '' )

Counts how many terms are in taxonomy.


Description

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


Parameters

$args

(Optional) Array or string of arguments. See WP_Term_Query::__construct() for information on accepted arguments.

Default value: array()

$deprecated

(Optional) Argument array, when using the legacy function parameter format.<br> If present, this parameter will be interpreted as $args, and the first function parameter will be parsed as a taxonomy or array of taxonomies.<br>

Default value: ''


Return

(string|WP_Error) Numeric string containing the number of terms in that taxonomy or WP_Error if the taxonomy does not exist.


Source

File: wp-includes/taxonomy.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);
}


Changelog

Changelog
Version Description
5.6.0 Changed the function signature so that the $args array can be provided as the first parameter.
2.3.0 Introduced.