I have term with tid=9 (sublevel 3). It is nested under 2 other terms. I use following code to get names of its parent terms:
<?php
//term id of term that you are checking for top parent
$term_tid = '9';
//this will be your top parent term if any was found
$top_parent_terms = array();
$parent_terms = taxonomy_get_parents_all($term_tid);
//top parent term has no parents so find it out by checking if it has parents
foreach($parent_terms as $parent) {
$parent_parents = taxonomy_get_parents_all($parent->tid);
if ($parent_parents != false) {
//this is top parent term
$top_parent_term[] = $parent;
}
return $top_parent_term;
}
?>
Problem: As a result I am getting "array" with error: "Notice: Array to string conversion in php_eval() " instead of terms names. I tried bunch of other solutions but none of them work or I get same error (for example here https://api.drupal.org/comment/59421#comment-59421)