1

How can I change the below code to display only the selected terms in the node. right now all terms which are defined in the vocabulary is displayed

<?php 
$items = taxonomy_vocabulary_machine_name_load('test_categories');
$taxonomy = taxonomy_get_tree($items->vid);
foreach($taxonomy as $key => $items):
  print $items->name;
endforeach;
?>

2 Answers 2

0

If you want to print a selected taxonomy value in a node, try this way..

$node = node_load($nid);
//If you have multiple values use foreach.
$tid = $node->yourfieldname['und'][0]['tid'];//if you are using term reference.
$term = taxonomy_term_load($tid);
print $term->name;
2
  • I'm using multiple values and i tried but still not working with me Commented Sep 19, 2015 at 16:22
  • did u tried it in a loop..?? can u show d code..??
    – Abin
    Commented Sep 22, 2015 at 4:09
0

For specific node you need to use $info = node_load($nid) where you find your field value using $info->field_name. Using that field you can use foreach something like foreach($info->field_name as as $key => $items).

1
  • please can you explain it in example Commented Sep 17, 2015 at 6:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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