wp_count_terms()

This core WordPress function works with CPT-onomies and DOES NOT require the CPT-onomy class.

Description

Count how many terms are in a CPT-onomy.

Usage

wp_count_terms( 						string
						$cpt_onomy
						, 						string|array
						$args
						 );

Parameters

$cpt_onomy (string) (required)
Default: none
Name of the CPT-onomy.

$args (string|array) (optional)
Default: array
Arguments to customize which data is counted.
For information on how to customize the $args parameter, refer to the WordPress codex.

Return Values

(int) How many terms are in the $cpt_onomy.

Examples

Display the total number of terms.

<?php echo 'There are ' . wp_count_terms( 'actors', array( 'hide_empty' => false ) ) . ' terms in the actors CPT-onomy.'; ?>

Display the number of terms who have been assigned to an object.

<?php echo 'There are ' . wp_count_terms( 'actors', array( 'hide_empty' => true ) ) . ' terms in the actors CPT-onomy who have been assigned to an object.'; ?>

Notes

  • Prior to WordPress version 3.1, you must use $cpt_onomy->wp_count_terms().
  • You must use $cpt_onomy->wp_count_terms() prior to version 1.0.2.
  • The 'hide_empty' => true argument does not work prior to version 1.0.2.

WordPress Codex

For more information, refer to the WordPress codex.