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)
$terms = $query->execute();


Done =)

Reference: Drupal’s EntityFieldQuery and Taxonomy


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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