How to fetch all the terms of a vocabulary in Drupal 8?

Since taxonomy term is an entity all the Terms for a specific vocabulary can be fetched using following entity query.

$query = \Drupal::entityQuery('taxonomy_term')->condition('vid', 'YOUR_VOCABULARY');
$result = $query->execute();
foreach ($result as $key => $value) {
      $result[$key] = Term::load($value)->getName();
}

$result can used for getting key value array of TID and Term Name.

Tags