I am trying to get a custom field assigned to taxonomy. I have tried this:
$vid = 'zeme';
$terms =\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid);
$terms is now storing all the terms from the vocabulary called 'zeme'. The problem is when I print this variable, it doesnt show the custom field that I need to get. Any idea how can I get this custom field? My code looks like this:
$vid = 'zeme';
$terms =\Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid);
foreach ($terms as $term) {
$term_data[] = array(
'id' => $term->tid,
'name' => $term->name
);
}
Here is the
loadTree functionofficial documentation : TermStorage::loadTreeWhen you use the
loadTreefunction, it will only get you the minimal datas to save execution time. You can see there is a$load_entitiesparameter set tofalseby default.So if you want to get all the datas of each of your taxonomy terms, you have to set
$load_entitiestotrue.