Drupal 8 custom type content, getting values for a field of type Taxonomy (hence, Entity Reference), which can have multiple values in the field I have a custom content type (we'll call it 'book')... and it has a field  (We'll call the field 'category') which is of type Taxonomy Term and which can hold say ten items.

I can load the content programmatically:

$nids = \Drupal::entityQuery('node')-&gt;condition('type','custom content type machine name')-&gt;execute();

        $nodes =  \Drupal\node\Entity\Node::loadMultiple($nids);


I can then scroll through the items of node using something like

  foreach ($node as $node_item){
      echo $node_item-&gt;title
   }


However, how would I output the content of the reference entity 'category' ... say if category has 3 items assigned to it, it would be something like this:

  foreach ($node as $node_item){
      echo $node_item-&gt;title,
      echo $node_item-&gt;category[0]-&gt;target_id,
      echo $node_item-&gt;category[1]-&gt;target_id,
      echo $node_item-&gt;category[2]-&gt;target_id,
   }


But, this does not work...

There is the suggestion that $node_item->category has to be loaded as an entity reference but using $node->cateogry->referenceEntities () does not load anything.

Any ideas?  Thanks in advance.
I think $node_item->category->referencedEntities() is what you want to use.

You have misspelled the method in your question.

 if ($node_item-&gt;category-&gt;isEmpty() === FALSE) {
    $vars = [];
    // Get referenced entities and add each to array of terms.
    foreach ($node_item-&gt;category-&gt;referencedEntities() as $term) {
      $vars[] = [
        'name' =&gt; $term-&gt;label(),
        'phone' =&gt; $term-&gt;field_phone_number-&gt;value,
        'email' =&gt; $term-&gt;field_email_address-&gt;value,
      ];
    }
  }