Title: wp_count_terms
Published: April 25, 2014
Last modified: February 24, 2026

---

# wp_count_terms( array|string $args = array(), array|string $deprecated ): string|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_count_terms/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_count_terms/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_count_terms/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_count_terms/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_count_terms/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_count_terms/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_count_terms/?output_format=md#wp--skip-link--target)

Counts how many terms are in taxonomy.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_count_terms/?output_format=md#description)󠁿

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

{@internal The `$deprecated` parameter is parsed for backward compatibility only.}

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_count_terms/?output_format=md#parameters)󠁿

 `$args`array|stringoptional

Array or string of arguments. See [WP_Term_Query::__construct()](https://developer.wordpress.org/reference/classes/wp_term_query/__construct/)
for information on accepted arguments.

Default:`array()`

`$deprecated`array|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.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_count_terms/?output_format=md#return)󠁿

 string|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) 
Numeric string containing the number of terms in that taxonomy or [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
if the taxonomy does not exist.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_count_terms/?output_format=md#source)󠁿

    ```php
    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 );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/taxonomy.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/taxonomy.php#L1950)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/taxonomy.php#L1950-L1979)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_count_terms/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_is_numeric_array()](https://developer.wordpress.org/reference/functions/wp_is_numeric_array/)`wp-includes/functions.php` |

Determines if the variable is a numeric-indexed array.

  | 
| [get_terms()](https://developer.wordpress.org/reference/functions/get_terms/)`wp-includes/taxonomy.php` |

Retrieves the terms in a given taxonomy or list of taxonomies.

  | 
| [taxonomy_exists()](https://developer.wordpress.org/reference/functions/taxonomy_exists/)`wp-includes/taxonomy.php` |

Determines whether the taxonomy name exists.

  | 
| [wp_parse_args()](https://developer.wordpress.org/reference/functions/wp_parse_args/)`wp-includes/functions.php` |

Merges user defined arguments into defaults array.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/wp_count_terms/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_count_terms/?output_format=md#)

| Used by | Description | 
| [WP_REST_Term_Search_Handler::search_items()](https://developer.wordpress.org/reference/classes/wp_rest_term_search_handler/search_items/)`wp-includes/rest-api/search/class-wp-rest-term-search-handler.php` |

Searches terms for a given search request.

  | 
| [WP_Sitemaps_Taxonomies::get_max_num_pages()](https://developer.wordpress.org/reference/classes/wp_sitemaps_taxonomies/get_max_num_pages/)`wp-includes/sitemaps/providers/class-wp-sitemaps-taxonomies.php` |

Gets the max number of pages available for the object type.

  | 
| [WP_REST_Terms_Controller::get_items()](https://developer.wordpress.org/reference/classes/wp_rest_terms_controller/get_items/)`wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php` |

Retrieves terms associated with a taxonomy.

  | 
| [WP_Terms_List_Table::prepare_items()](https://developer.wordpress.org/reference/classes/wp_terms_list_table/prepare_items/)`wp-admin/includes/class-wp-terms-list-table.php` |  | 
| [wp_nav_menu_item_taxonomy_meta_box()](https://developer.wordpress.org/reference/functions/wp_nav_menu_item_taxonomy_meta_box/)`wp-admin/includes/nav-menu.php` |

Displays a meta box for a taxonomy menu item.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_count_terms/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.6.0](https://developer.wordpress.org/reference/since/5.6.0/) | Changed the function signature so that the `$args` array can be provided as the first parameter. | 
| [2.3.0](https://developer.wordpress.org/reference/since/2.3.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_count_terms%2F)
before being able to contribute a note or feedback.