Display parent taxonomy term
Last updated on
30 April 2025
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;
}
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion