Drupal 7 – Select node by language using EntityFieldQuery

Here is an example to select entities by the current language in EntityFieldQuery.

// Get the current language
global $language;

// Setup the EntityFieldQuery
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', '<CONTENT TYPE>') // ex. article
  ->propertyCondition('status', 1) // published nodes
  ->propertyCondition('language', $language->language, '='); // filter by current language

// Execute the query
$result = $query->execute();

 

Done =)

Advertisement

One thought on “Drupal 7 – Select node by language using EntityFieldQuery”

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 )

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.