Drupal 7 – Get mulitple nodes using EntityFieldQuery and node_load_multiple()

We tried to get specific nodes using EntityFieldQuery.
Drupal 7 – Get specific nodes using EntityFieldQuery

It returns a list of node ids which fulfill the query conditions. The next step is usually the retrieval of the nodes by the node ids. This can be done by the following example using node_load_multiple().

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', '<CONTENT TYPE>') // ex. article
  ->propertyCondition('uid', $uid) // node written by a specific user
  ->propertyCondition('status', 1) // published nodes
  ->propertyCondition('created', REQUEST_TIME - 3600, '>='); // created within the past 1 hour
$result = $query->execute();

if (isset($result['node'])) {
  $nids = array_keys($result['node']);
  return node_load_multiple($nids);
} else {
  return array();
}

 

Done =)

Reference: Drupal API - node_load_multiple

About these ads

2 thoughts on “Drupal 7 – Get mulitple nodes using EntityFieldQuery and node_load_multiple()

  1. Pingback: Drupal 7 – Customize the exposed filter selection list | Eureka!

  2. Pingback: Drupal 7 – Get specific nodes using EntityFieldQuery | Eureka!

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