I am able to retrieve taxonomy terms programmatically, (as long as I only want to reference the default fields, 'tid' and 'name'). But how do I access custom taxonomy fields?
$vid = 'MACHINE_NAME';
$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid);
foreach ($terms as $term) {
$tid = $term->tid;
$term_name = $term->name;
// REFERENCE CUSTOM FIELD VALUES HERE...
}
I have tried all manor of ways I have seen, but can't get any of them working, eg:
$value = $term->FIELD_NAME->value;
$value = $term->get('FIELD_NAME')->getValue();
How do I reference custom taxonomy term fields by their machine name, from what is returned by getStorage('taxonomy_term')->loadTree($vid)?
value
. What type of field is it?