This question already has an answer here:

I added a required field in a Job type node later. So existing nodes don't have that particular field value. I want to include all such field values. But how can I do it?

Here is query sample:

$query->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', array('central_government_vacancy','psu_vacancy','state_government_vacancy'))
    ->propertyCondition('status', 1)
    -> fieldCondition('field__expired_processed', 'value', 'NULL', '=')  //I'm looking for this field
    ->fieldCondition('field_last_date_of_application', 'value', $date, '<=');

In the above code I want to find nodes having uninitialized field values : field_expired_processed.

!=, or using NULL to compare does not seem to work.

marked as duplicate by Clive Mar 11 '13 at 14:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


If you look on the fieldCondition documentation page you will see the following warning:

Note that entities with empty field values will be excluded from the EntityFieldQuery results when using this method.

Checking whether a field exists or not has been added to entityFieldQuery in Drupal 8, but unfortunately won't be backported to Drupal 7.

This means you must use standard SelectQuery in order to achieve this. You must join the table which contains your data, and check whether the fiels IS NULL. It would be something like:

$q = db_select('node', 'n');
$q->condition('n.type', 'central_government_vacancy', '=')
->addJoin('LEFT', 'field_data_field_expired_processed', 'f')
$r = $q->execute();

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