wp_count_terms
Count how many terms are in Taxonomy.
Description
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
if ( !function_exists( 'wp_count_terms' ) ) { require_once ABSPATH . WPINC . '/taxonomy.php'; } // Taxonomy name. $taxonomy = ''; // Optional. Array of arguments that get passed to get_terms(). // Default empty array. $args = array(); // NOTICE! Understand what this does before running. $result = wp_count_terms($taxonomy, $args);
Defined (1)
The function is defined in the following location(s).
- /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);
- }