wp_count_terms( array|string $args = array(), array|string $deprecated = '' ): string|WP_Error
- Since
- 2.3.0, 5.6.0
- Source
wp-includes/taxonomy.php:1944
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
$argsarray|stringoptional- Array or string of arguments. See WP_Term_Query::__construct() for information on accepted arguments. Default empty array.Default:
array() $deprecatedarray|stringoptional- Argument array, when using the legacy function parameter format. If present, this parameter will be interpreted as
$args, and the first function parameter will be parsed as a taxonomy or array of taxonomies. Default empty.Default:''
Return
string|WP_Error- Numeric string containing the number of terms in that taxonomy or WP_Error if the taxonomy does not exist.
Uses · 4
- taxonomy_exists()Determines whether the taxonomy name exists.
- wp_is_numeric_array()Determines if the variable is a numeric-indexed array.
- wp_parse_args()Merges user defined arguments into defaults array.
- get_terms()Retrieves the terms in a given taxonomy or list of taxonomies.
Used by · 5
- WP_REST_Term_Search_Handler::search_items()Searches terms for a given search request.
- WP_REST_Terms_Controller::get_items()Retrieves terms associated with a taxonomy.
- WP_Sitemaps_Taxonomies::get_max_num_pages()Gets the max number of pages available for the object type.
- WP_Terms_List_Table::prepare_items()
- wp_nav_menu_item_taxonomy_meta_box()Displays a meta box for a taxonomy menu item.
Source
function wp_count_terms( $args = array(), $deprecated = '' ) { $use_legacy_args = false; // Check whether function is used with legacy signature: `$taxonomy` and `$args`. if ( $args && ( is_string( $args ) && taxonomy_exists( $args ) || is_array( $args ) && wp_is_numeric_array( $args ) ) ) { $use_legacy_args = true; } $defaults = array( 'hide_empty' => false ); if ( $use_legacy_args ) { $defaults['taxonomy'] = $args; $args = $deprecated; } $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 );}History
Introduced in 2.3.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
5.6.0
Changed the function signature so that the
$args array can be provided as the first parameter.from the docblock2.3.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-includes/taxonomy.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.