Loading taxonomy term custom field data I have a vocabulary "holiday_types" with taxonomy terms "ski" and "beach". I have a custom field on these taxonomy terms "field_activityid" which relates to a legacy system.

I want to load all these terms so that as I loop through a list of regions I can add the taxonomy_term ID to an entity reference field, and I need to get the legacy activityid to query an external API.

I'm having issues with entityQuery not recognising 'holiday_types' as a bundle of taxonomy term, I tried 'type' too. I'm also not getting entityQueryAggregate working either so thought I'd pose the question here to see if there's a 'proper' way of querying custom fields on taxonomy terms.

Adding example here which produces "QueryException: 'bundle' not found"

$holidayTypesQuery = \Drupal::entityQueryAggregate('taxonomy_term');
$holidayTypesQuery-&gt;conditionAggregate('bundle', 'holiday_types');
$ids = $holidayTypesQuery-&gt;execute();
$storage = \Drupal::entityManager()-&gt;getStorage('taxonomy_term');
$entities = $storage-&gt;loadMultiple($ids);


If I change 'bundle' to 'vid' it errors with the following:

    Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42000]: 
Syntax error or access violation: 1305 FUNCTION purkidev.holiday_types does not exist: 
SELECT holiday_types(taxonomy_term_field_data.vid) 
AS vid_holiday_types 
FROM {taxonomy_term_data} base_table 
LEFT JOIN {taxonomy_term_field_data} taxonomy_term_field_data 
ON taxonomy_term_field_data.tid = base_table.tid 
INNER JOIN {taxonomy_term_field_data} taxonomy_term_field_data_2 
ON taxonomy_term_field_data_2.tid = base_table.tid 
HAVING (holiday_types(taxonomy_term_field_data_2.vid) = :db_placeholder_0); Array ( [:db_placeholder_0] =&gt; ) 
in Drupal\purkitest\Controller\PurkitestController-&gt;simple() (line 89 of /Users/steve/Sites/purkidev/modules/purkitest/src/Controller/PurkitestController.php).


Trying without Aggregate:

$holidayTypesTIDs = \Drupal::entityQuery('taxonomy_term')
  -&gt;condition('vid', 'holiday_types')-&gt;execute();
$taxonomyTermStorage = \Drupal::entityManager()-&gt;getStorage('taxonomy_term');
$holidayTypes = $taxonomyTermStorage-&gt;loadMultiple($holidayTypesTIDs);
foreach ($holidayTypes as $holidayType) {
  dpm($holidayType);
}


This works but when I dpm($holidayTypes) I don't get anything in the fields:

[fields:protected] =&gt; Array
    (
    )


...hence why I was trying aggregate as I thought it brought together the fields.

So, can I access the value of my field_activityid from here and if so how? Have tried various random things like 

dpm($holidayType-&gt;field_activityid-&gt;value()) 


which produces 

Call to undefined method Drupal\Core\Field\FieldItemList::value()


Following berdir's comments here's the latest whole function... which now works - thanks all for helping my syntax!

public function simple() {

$holidayTypesTIDs = \Drupal::entityQuery('taxonomy_term')
  -&gt;condition('vid', 'holiday_types')-&gt;execute();
$taxonomyTermStorage = \Drupal::entityManager()-&gt;getStorage('taxonomy_term');
$holidayTypes = $taxonomyTermStorage-&gt;loadMultiple($holidayTypesTIDs);

$markup = '';
foreach ($holidayTypes as $holidayType) {
  $markup .= "&lt;p&gt;Holiday Type: ";
  $markup .= $holidayType-&gt;getName();
  $markup .= "&lt;/p&gt;&lt;p&gt;TID: ";
  $markup .= $holidayType-&gt;id();
  $markup .= "&lt;/p&gt;&lt;p&gt;ActivityID: ";
  $markup .= $holidayType-&gt;field_activityid-&gt;value;
  $markup .= "&lt;/p&gt;&lt;p&gt;";
}

return array(
  '#markup' =&gt; $markup,
);


}
Your entity query works fine (without aggregate). dpm() doesn't work in D8 for content entities, try kint() instead, but that will also be misleading.

Your last attempt was almost correct: -&gt;value is a property (a magic property, actually), not a method. So this should work fine:

$holidayType-&gt;field_activityid-&gt;value


As referenced already in a few questions, have a look at http://wizzlern.nl/drupal/drupal-8-entity-cheat-sheet; it's a bit old but it's still a great overview of the Content Entity (Field) API.

If you do want to use dpm()/kint(), then always run it on $entity-&gt;toArray(). That will give you an array structure of the fields, you can translate that 1:1 to object properties and it will work fine. For deltas, use $holidayType-&gt;field_activityid[1]-&gt;value; not providing it defaults to delta 0.

And, no, you definitely don't want an aggregate query. You need that if you want to COUNT() or SUM() some values of your entities.