drupaldrupal-7drupal-taxonomy

drupal 7 taxonomy_vocabulary_machine_name_load did not show the fields


I have created a vocabulary and listed terms within it, in D7. I have added a field named "Icon Color". Now, within the view, I have added the code block as below which perfectly displayed the fields like tid, name, description but it did not show the field "Icon Color".

<?php
   $name = 'Programme';
   $myvoc = taxonomy_vocabulary_machine_name_load($name);
   $tree = taxonomy_get_tree($myvoc->vid);
   foreach ($tree as $term) { 
   print_r($term); 
   }
?>

The fields are listed within the vocabulary as below:

enter image description here


Solution

  • You must load the taxonomy using term id by taxonomy term load function. Hope the below code helps you.

    $name = 'YOUR_MACHINE_NAME';
    $myvoc = taxonomy_vocabulary_machine_name_load($name);
    $tree = taxonomy_get_tree($myvoc->vid);
    foreach ($tree as $term) { 
      $term = taxonomy_term_load($term->tid);
      print_r($term);
    }