How to get fields from taxonomy terms? 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()-&gt;getStorage('taxonomy_term')-&gt;loadTree($vid);
foreach ($terms as $term) {
    $tid = $term-&gt;tid;
    $term_name = $term-&gt;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-&gt;FIELD_NAME-&gt;value;
$value = $term-&gt;get('FIELD_NAME')-&gt;getValue();


How do I reference custom taxonomy term fields by their machine name, from what is returned by getStorage('taxonomy_term')->loadTree($vid)?
The entities aren't loaded by default (for performance reasons), but TermStorage::loadTree takes a $load_entities parameter:


  If TRUE, a full entity load will occur on the term objects. Otherwise they are partial objects queried directly from the {taxonomy_term_data} table to save execution time and memory consumption when listing large numbers of terms. Defaults to FALSE.


That will give you access to the fields. E.g.

$terms = \Drupal::entityTypeManager()
  -&gt;getStorage('taxonomy_term')
  -&gt;loadTree($vid, 0, NULL, TRUE);