How to loop through a taxonomy vocabulary to find the top category in a nested tree?
I would recommend using taxonomy_get_parents_all(). If you have a vocabylary that looks like:


Vocabulary

Child 1 (tid=1)

Child 1.1 (tid=3)

Child 2 (tid=2)



Then you can do:

&lt;?php
$parents = taxonomy_get_parents_all(3);
$top_category = array_pop($parents);


Will give you the term for tid 1.