I would like to build a query for all taxonomy terms of a specific bundle.

$terms = \Drupal::entityQuery('taxonomy_term')

This returns an error 'type' not found.

How do I query taxonomy terms of a specific bundle (specific vocabulary)?


Since you are using Drupal 8 you should use the entityTypeManager for this task.

This code will load all terms from the mail_template vocabulary.

$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties([
  'vid' => 'mail_template',

This works :

$terms = \Drupal::entityQuery('taxonomy_term')
            $termData = \Drupal::entityTypeManager()
            ->loadByProperties(['vid' => 'vocabulary_name']);

Always works :D

If you also have the name it is

->loadByProperties(['name' => $term, 'vid' => 'selected_keyword']);

If you need the id from what is returned

// returns an array with the tid as the key so foreach ($termData as $key => $value){ $termId = $key; // I need the first and only break; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.