How can I get the parent term in a taxonomy with a hierarchy? I have a node that is tagged with a taxonomy term which is part of a hierarchy of terms such as "state >> county."

As the user has selected one of the "county" tags, how can I get the name of the parent term?
taxonomy_get_parents() returns all the parent terms for the taxonomy term with the ID passed as argument.
The value returned from the function is an array having the following structure:


array(
  'term id' => [taxonomy term object]
)


The taxonomy term object contains a property for each of the fields contained in the "term_data" table.

The code used from the function is essentially the following one.

$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-&gt;$key] = $parent;
}


As you see, it doesn't return the parent terms of the parent terms of the one passed as argument. For that you need taxonomy_get_parents_all(), which executes the following code.

  if ($tid) {
    $parents[] = taxonomy_get_term($tid);
    $n = 0;
    while ($parent = taxonomy_get_parents($parents[$n]-&gt;tid)) {
      $parents = array_merge($parents, $parent);
      $n++;
    }
  }


The function returns all the parent terms in the hierarchy.