I have x nodes with field named "thefield". My script is checking "thefield" and if he does so the right value is updated.

How can i get from node just one field for check and didnt load full entity (node_load)?

5 Answers 5


I would use a db_query to find all nodes that that field appears on and then update them with a node_load here is the code:

$result = db_query('SELECT f.entity_id FROM {field_data_field_thefield} f');
foreach ($result as $record) {
    $node = node_load($record->entity_id);
    // update node

You can either do it programmatically or using views.

Using Views : Create a view page and under the fields section add the following fields:

Node id and the specific field you would like to update.

Update the filter condition as follows: Node type = 'YOUR NODE TYPE' AND "Your required field" = NOT NULL

The output of this view will be the node ids of all those node which will be having a values assigned to the specific field.

If this didn't helped you, please let me know, will solve it in a different way


  • Hi, im looking for programatical way. Becouse views object isnt good for performance in this case.
    – Patrick
    Jul 29, 2014 at 10:32
$nid = 1;
$thefield = db_select('field_data_field_thefield', 'f');
  ->condition('f.entity_id', $nid, '=');

  Do Something...

You could use a db_query instead of db_select to make it even quicker

  • what mean 'f' parameter?
    – Patrick
    Jul 29, 2014 at 10:59
  • f is just an alias for the field table. I have just updated the name to better reflect how it will be stored in the database
    – pete80
    Jul 29, 2014 at 11:11

If you want to update any field in node , then better to use node_load() function. Because if you use any custom select or update query then

  • first thing you need to update it in all the tables (main and revision tables).
  • Second thing, drupal events will not trigger that is attached with updation.

If you still want to do it manually by db_select() and db_query()

Hope it will help!

  • In my case, i need to check all nodes of one type just for one field, so its better for performance when i dont "build" full node, sure for write i will get full node
    – Patrick
    Jul 29, 2014 at 14:15
  • Then i don't see any other way than custom queries. But you check the fields easily but during updation you need to take care of all the conditions and pattern in which the data need to be wrtite in the tables. Jul 31, 2014 at 5:18

The field API allows you to load/attach just one field in a list of entities with field_attach_load(). This approach is field storage agnostic, invokes field-level hooks, and reads from the field cache if possible.

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.