Whether to assign only the lowest level taxonomy term to a page, or also assign the parent terms so that they display, is a frequent issue. This snippet allows you to display a parent term of a term already assigned to your entity. Note that this is not actually a term reference, so doing this will not allow you to list this page using the taxonomy system.

But if your term reference field is called myterm (field_myterm), you can use this to display a parent term. This assumes that there is just one parent term.

$p = taxonomy_get_parents($entity->field_myterm['und'][0]['tid']);
foreach($p AS $parent) {
  $entity_field[0]['value'] = $parent->name;
}

Comments

kaizerking’s picture

how to get parent terms of selected terms in a multi value field group by root?