taxonomy_get_parents

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

Find all parents of a given term ID.

▾ 6 functions call taxonomy_get_parents()

taxonomy_form_term in modules/taxonomy/taxonomy.admin.inc
Form function for the term edit form.
taxonomy_get_parents_all in modules/taxonomy/taxonomy.module
Find all ancestors of a given term ID.
taxonomy_term_delete in modules/taxonomy/taxonomy.module
Delete a term.
taxonomy_term_page in modules/taxonomy/taxonomy.pages.inc
Menu callback; displays all nodes associated with a term.
taxonomy_tokens in modules/taxonomy/taxonomy.tokens.inc
Implement hook_tokens().
_forum_parent_select in modules/forum/forum.admin.inc
Returns a select box for available parent terms

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
 
 

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.