Drupal 7: Load all terms in a Taxonomy vocabulary

There still isn’t a function for this, and the conditions in taxonomy_term_load_multiple have been deprecated, so an EntityFieldQuery is the only (and recommended) way to do this:

  $query = new EntityFieldQuery();
  $result = $query
  ->entityCondition('entity_type', 'taxonomy_term')
  ->propertyCondition('vid', 2, '=') // for vocabulary id 2
  ->execute();

Not too bad, I guess, but it just feels like something that should be doable with a single function call. Maybe I’ll add a wrapper function to a utility module or something:

  function taxonomy_term_get_by_vid($vid) {
    $query = new EntityFieldQuery();
    $result = $query
    ->entityCondition('entity_type', 'taxonomy_term')
    ->propertyCondition('vid', (int) $vid, '=')
    ->execute();
    return $result['taxonomy_term'];
  }
This entry was posted in Uncategorized. Bookmark the permalink.

3 Responses to Drupal 7: Load all terms in a Taxonomy vocabulary

  1. Not true says:

    $terms = taxonomy_term_load_multiple(array(), array(‘vid’ => $vid));

    • amplifier says:

      Yes, that’ll work (for now), but like I mentioned, the conditions parameter is deprecated and will be removed in Drupal 8.

  2. Rich says:

    Thanks! I was just doing the same and thought “this should be easier”; your post helped me realise, yes, it should, but it isn’t, so live with it!

Leave a Reply

Your email address will not be published. Required fields are marked *