Skip to content

Instantly share code, notes, and snippets.

@brooke-heaton
Last active March 3, 2017 02:49
Show Gist options
  • Save brooke-heaton/6755b15e6357f4bc27bf8419105af642 to your computer and use it in GitHub Desktop.
Save brooke-heaton/6755b15e6357f4bc27bf8419105af642 to your computer and use it in GitHub Desktop.
Get Count of Taxonomy Terms per Vocabulary ID
<?php
/**
* This Drupal 7 helper function will return and echo the count of
* taxonomy terms by vocabulary
* @param $vid - integer for vocabulary id
*/
function GetCountTaxonomyTermsByVocab($vid) {
$query = new EntityFieldQuery;
$terms = $query
->entityCondition('entity_type', 'taxonomy_term')
->propertyCondition('vid', $vid)
->execute();
$count_terms = count($terms['taxonomy_term']);
echo "There are $count_terms terms in the $vid Vocabulary\n";
return $count_terms;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment