0

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

$terms = \Drupal::entityQuery('taxonomy_term')
  ->condition('type','mail_template')
  ->execute();

This returns an error 'type' not found.

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

0

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',
]);
| improve this answer | |
2

This works :

$terms = \Drupal::entityQuery('taxonomy_term')
  ->condition('vid','mail_template')
  ->execute();
| improve this answer | |
0
            $termData = \Drupal::entityTypeManager()
            ->getStorage('taxonomy_term')
            ->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; }

| improve this answer | |

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.