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?

1 Answer 1

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();
1
  • 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
    Commented Nov 1, 2015 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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