The standard for fetching specific nodes from the database in Drupal 7 goes something like this:

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node');
$query->entityCondition('bundle', 'page');
$query->fieldCondition('field_category', 'value', $category_id);

$result = $query->execute();
$nids = array_keys($result['node']);
$nodes = node_load_multiple($nids);

For better performance, is there any way to specify that I want to load only certain fields (the title for example) of the nodes instead of loading all their their fields?

I prefer a solution that doesn't use SQL to benefit from all the goodies Drupal functions offer (reliability, caching results, future proofed, ...).

Thank you.


No, there isn't. EFQ can only return the entity id's.

While there might be ways around it, there is a logical reason for that: Modules might alter the values of those fields in various hooks, there is no guarantee that the directly returned values are the same as when loading an entity.

  • Thanks for the answer. But what do you recommend I use if I, let's say, want to fetch the titles for 500 nodes? what's the most efficient way of doing so? Thanks again!
    – Mario Awad
    Aug 14 '12 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.