Last updated April 13, 2012. Created by drm on April 13, 2012.
Log in to edit this page.
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 now 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.
<?php
$p = taxonomy_get_parents($entity->field_myterm['und'][0]['tid']);
foreach($p AS $parent) {
$entity_field[0]['value'] = $parent->name;
}
?>