1

I am trying to select an Entity with a condition on the node id.
Here's the query I use:

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'event')
    ->propertyCondition('status', NODE_PUBLISHED)
    ->fieldCondition('nid', 'value', $id, '=')
    ->range($page, 1);
$result = $query->execute();

I get the following error:

EntityFieldQueryException: Unknown field: nid in EntityFieldQuery->addFieldCondition()

How can I resolve this issue?

4

For EFQ, you need to filter on the entity condition column entity_id which is the node id.

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
    ->entityCondition('entity_id', $id)
    ->entityCondition('bundle', 'event')
    ->propertyCondition('status', NODE_PUBLISHED)
    ->range($page, 1);
$result = $query->execute();
  • Thank you! I feel bad for not noticing that I was applying the filter to the fields and not the entity... I should get some rest. Thanks! – acanana Nov 1 '15 at 17:39

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.