| 5 taxonomy.module | taxonomy_get_parents_all($tid) |
| 6 taxonomy.module | taxonomy_get_parents_all($tid) |
| 7 taxonomy.module | taxonomy_get_parents_all($tid) |
Find all ancestors of a given term ID.
3 calls to taxonomy_get_parents_all()
1 string reference to 'taxonomy_get_parents_all'
File
- modules/
taxonomy/ taxonomy.module, line 921 - Enables the organization of content into categories.
Code
function taxonomy_get_parents_all($tid) {
$cache = &drupal_static(__FUNCTION__, array());
if (isset($cache[$tid])) {
return $cache[$tid];
}
$parents = array();
if ($term = taxonomy_term_load($tid)) {
$parents[] = $term;
$n = 0;
while ($parent = taxonomy_get_parents($parents[$n]->tid)) {
$parents = array_merge($parents, $parent);
$n++;
}
}
$cache[$tid] = $parents;
return $parents;
}
Login or register to post comments
Comments
Return value
Note: The [0] element of the array returned by this function is the tern you reference when you call the function. E.g.
$myarray=taxonomy_get_parents_all(200);
print $myarray[0]['tid'];
Results: 200
To be more accurate the whole
To be more accurate the whole array is flipped. So if you have structure like A -> B -> C -> D and you are trying to get parents for D you'll end up with
array(0 => D (term object),
1 => C (term object),
2 => B (term object),
3 => A (term object)
);