taxonomy_get_parents

Versions
4.6 – 7
taxonomy_get_parents($tid, $key = 'tid')

Find all parents of a given term ID.

▾ 5 functions call taxonomy_get_parents()

taxonomy_del_term in modules/taxonomy.module
taxonomy_form_term in modules/taxonomy.module
taxonomy_get_parents_all in modules/taxonomy.module
Find all ancestors of a given term ID.
taxonomy_term_page in modules/taxonomy.module
Menu callback; displays all nodes associated with a term.
_forum_parent_select in modules/forum.module
Returns a select box for available parent terms

Code

modules/taxonomy.module, line 814

<?php
function taxonomy_get_parents($tid, $key = 'tid') {
  if ($tid) {
    $result = db_query(db_rewrite_sql('SELECT t.tid, t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.parent = t.tid WHERE h.tid = %d ORDER BY weight, name', 't', 'tid'), $tid);
    $parents = array();
    while ($parent = db_fetch_object($result)) {
      $parents[$parent->$key] = $parent;
    }
    return $parents;
  }
  else {
    return array();
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.