I am attempting to use the entity-field-query API to see if any node of referee content type has custom field that equals x. I've looked at dozens of code examples and references. (Included below)

If it is relevant I am executing this code as a custom PHP action in Drupal rules.

My problem is when the code is executed I get the below error:

EntityFieldQueryException: Unknown field: field_referee_id‎ in EntityFieldQuery->addFieldCon
dition() (line 817 of /home/scienceorg/public_html/includes/entity.inc).

(The field does exist on the referee content type.)

My code:


$query = new EntityFieldQuery();
    ->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'referee')
    ->fieldCondition('field_referee_id‎', 'value', '1', '=');
    $result = $query->execute();

Further information: If I remove the field condition line from the above code it works perfectly. So the problems seems to be around finding the field_referee_id.

Code references and examples

EntityFieldQuery condition


Alternative answer: If you don't know what is causing the above problem I will accept alternative methods of achieving the same outcome as the correct answer.

  • You could try running this efq in à custom module, to make sure that the efq itself is working (might be a rules problem) Also, wat type is that field? If its annentityreference field you will need to replace value with target_id. – Guardian Feb 19 '16 at 6:13
  • I might have to go the custom module route if I can't work it out. The field type is Integer and the widget is marked as a text field. Is the column still "value" for integers? – sephiith Feb 19 '16 at 9:32

The code above seems right only problem here might be the machine name of the field is not same as the one given in ->fieldCondition('field_referee_id‎', 'value', '1', '='); or the field might be multivalued field, for multivalued field in place of '=' 'IN' should be used.

  • I've switched it to IN and still the same PHP error. I've copied the machine name directly from the content type fields page so that has to be right. Do you know of any other methods for seeing if any nodes of a certain content have have a custom field value of x? – sephiith Feb 19 '16 at 11:30
  • It works as it is written. You can query the field table directly for checking the value of the field and can get entity id out of that table having the referee_id and check for the bundle within the same query. – Neelam Chaudhary Feb 19 '16 at 11:46
  • How would I go about that? – sephiith Feb 19 '16 at 11:47
  • $query = db_select('field_data_field_referee_id'); $query->condition('field_referee_id_value', 1); $query->condition('bundle', 'referee'); $query->fields('field_data_field_referee_id', array('entity_id')); This query might help you. – Neelam Chaudhary Feb 19 '16 at 11:50
  • When I do a var_dump($result) that code isn't showing me anything on the referee content types. Would you be able to explain what $query->fields('field_data_field_referee_id', array('entity_id')); is doing differently to ->fieldCondition('field_referee_id‎', 'value', '1', '=');? (It doesn't look like it's comparing it with the value 1) – sephiith Feb 19 '16 at 12:17

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.