Uses
| Uses | Description |
|---|---|
| wp-includes/functions.php: wp_parse_args() | Merge user defined arguments into defaults array. |
| wp-includes/taxonomy.php: get_terms() | Retrieve the terms in a given taxonomy or list of taxonomies. |
Count how many terms are in Taxonomy.
Default $args is ‘hide_empty’ which can be ‘hide_empty=true’ or array(‘hide_empty’ => true).
(string) (Required) Taxonomy name.
(array|string) (Optional) Array of arguments that get passed to get_terms().
Default value: array()
(array|int|WP_Error) Number of terms in that taxonomy or WP_Error if the taxonomy does not exist.
File: wp-includes/taxonomy.php
function wp_count_terms( $taxonomy, $args = array() ) {
$defaults = array(
'taxonomy' => $taxonomy,
'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( $args );
} | Version | Description |
|---|---|
| 2.3.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_count_terms