1

I want to count taxonomy terms for one (or per) vocabulary. I know, it can be done via views with aggregation but I wonder if there is another way to do this without using views.

There is a taxonomy vocabulary. There are terms in this vocabulary. I want to learn how many terms are there in this vocabulary.

Is there a method to show term counts as node count below?

<?php $counter = db_query("SELECT count(nid) FROM {node} WHERE node.type='page' AND node.status=1")->fetchField(); ?>

1 Answer 1

4

For count the number of term in a vocabulary you can use this method : taxonomy_get_tree($vocabulary_id). It will returns all the terms of the vocabulary in an array. After that, you only have to get the size of the array.

Example :

$terms_array = taxonomy_get_tree(9); //9 is the vocabulary ID.
$terms_nb = sizeof($terms_array); // $terms_nb = your number of terms.
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.