4.6 taxonomy.module taxonomy_get_related($tid, $key = 'tid')
4.7 taxonomy.module taxonomy_get_related($tid, $key = 'tid')
5 taxonomy.module taxonomy_get_related($tid, $key = 'tid')
6 taxonomy.module taxonomy_get_related($tid, $key = 'tid')

Find all term objects related to a given term ID.

1 call to taxonomy_get_related()
taxonomy_form_term in modules/taxonomy/taxonomy.admin.inc
Form function for the term edit form.


modules/taxonomy/taxonomy.module, line 762
Enables the organization of content into categories.


function taxonomy_get_related($tid, $key = 'tid') {
  if ($tid) {
    $result = db_query('SELECT t.*, tid1, tid2 FROM {term_relation}, {term_data} t WHERE (t.tid = tid1 OR t.tid = tid2) AND (tid1 = %d OR tid2 = %d) AND t.tid != %d ORDER BY weight, name', $tid, $tid, $tid);
    $related = array();
    while ($term = db_fetch_object($result)) {
      $related[$term->$key] = $term;
    return $related;
  else {
    return array();


I need to establish a "dependency" relation between two terms. Let's say I define my dependencies using relationships, like "TermA depends on TermB", storing this as a relation between TermA and TermB. Now, if I want to find the terms that TermA depends on, would it make sense to modify this query to only take the relationships that have ONLY the "tid1" field as the tid of TermA, and not "tid2" too?

By modifying I mean copy-pasting the code to a different, custom function, and not hacking the core.