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 =)

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