1

I want to display taxonomy term from it's id. I have the following code that get's me id of this term but I don't how to convert this id into term name to display it.

function menu_custom_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  dpm($items);
  $element = array();
  foreach ($items as $delta => $item) {     
    $element[$delta] =  l(check_plain($item['target_id']));    
    }  
  return array(
    0 => array(
      '#markup' => theme('item_list', array('items' => $item)),
    ),
  );
  return theme('item_list', array());
}
0

To get the taxonomy term name from ID.

function menu_custom_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  dpm($items);
  $element = array();
  foreach ($items as $delta => $item) { 
    $taxonomy = taxonomy_term_load($item['target_id']);
    $element[$delta] = $taxonomy->name;
  }  
  return array(
    0 => array(
      '#markup' => theme('item_list', array('items' => $item)),
    ),
  );
  return theme('item_list', array());
}

$taxonomy->name will give you name of taxonomy term.

I hope this will help. Thanks

  • it gaves me same id – rick Jul 1 '16 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.