Drupal 7 – Get taxonomy terms by EntityFieldQuery

The EntityFieldQuery is not limited to node, it can be used to retrieve any entity types in Drupal 7. Here comes an example about getting taxonomy terms with EntityFieldQuery.

I would like to retrieve all terms with of a specific vocabulary which has vid = 1 with the descending weight order.

$query = new EntityFieldQuery;
$query->entityCondition('entity_type', 'taxonomy_term')
  ->propertyCondition('vid', 1)
  ->propertyOrderBy('weight');
 
$terms = $query->execute();

 

Done =)

Reference: Drupal’s EntityFieldQuery and Taxonomy
http://blog.rapiddg.com/2012/02/drupals-entityfieldquery-and-taxonomy/

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.