taxonomy_get_parents
- Versions
- 4.6 – 7
taxonomy_get_parents($tid, $key = 'tid')
Find all parents of a given term ID.
Code
modules/taxonomy/taxonomy.module, line 578
<?php
function taxonomy_get_parents($tid, $key = 'tid') {
if ($tid) {
$query = db_select('taxonomy_term_data', 't');
$query->join('taxonomy_term_hierarchy', 'h', 'h.parent = t.tid');
$result = $query
->addTag('translatable')
->addTag('term_access')
->fields('t')
->condition('h.tid', $tid)
->orderBy('weight')
->orderBy('name')
->execute();
$parents = array();
foreach ($result as $parent) {
$parents[$parent->$key] = $parent;
}
return $parents;
}
else {
return array();
}
}
?>Login or register to post comments 