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/

Advertisements

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 )

Google+ photo

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

Connecting to %s