wp_count_terms

Count how many terms are in Taxonomy.

Description

(array|int|WP_Error) wp_count_terms( (string) $taxonomy, (array) $args = array() ); 

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

Returns (array|int|WP_Error)

Number of terms in that taxonomy or WP_Error if the taxonomy does not exist.

Parameters (2)

0. $taxonomy (string)
Taxonomy name.
1. $args — Optional. (array) => array()
Array of arguments that get passed to get_terms(). Default empty array.

Usage

  1. if ( !function_exists( 'wp_count_terms' ) ) { 
  2. require_once ABSPATH . WPINC . '/taxonomy.php'; 
  3.  
  4. // Taxonomy name. 
  5. $taxonomy = ''; 
  6.  
  7. // Optional. Array of arguments that get passed to get_terms(). 
  8. // Default empty array. 
  9. $args = array(); 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = wp_count_terms($taxonomy, $args); 
  13.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/taxonomy.php  
  1. function wp_count_terms( $taxonomy, $args = array() ) { 
  2. $defaults = array('hide_empty' => false); 
  3. $args = wp_parse_args($args, $defaults); 
  4.  
  5. // backward compatibility 
  6. if ( isset($args['ignore_empty']) ) { 
  7. $args['hide_empty'] = $args['ignore_empty']; 
  8. unset($args['ignore_empty']); 
  9.  
  10. $args['fields'] = 'count'; 
  11.  
  12. return get_terms($taxonomy, $args);