2

This seems like it would be a common need but I don't see how it can be done with the operators available. I have a taxonomy reference field that allows multiple values. I would like to construct an EntityFieldQuery that selects the entity if at least one of the tid's is in the given array.

$query->fieldCondition('field_tags', 'tid', $tid_array, 'CONTAINS_ONE');
7

All you need is:

$query->fieldCondition('field_tags', 'tid', $tid_array);

From EntityFieldQuery::addFieldCondition(): "The operator can be omitted, and will default to 'IN' if the value is an array, or to '=' otherwise."

  • I know that the operator defaults to 'IN', but does this return every entity where even one of the multiple-valued field values is in the array? It seems to be returning zero rows for me, but I may have a separate problem. – Joe Beuckman Jul 23 '12 at 22:00
  • Works for me. Yes it returns every entity where even one of the multiple-valued field values is in the array. I'm using Drupal 7.15. Cheers. – Mario Awad Sep 19 '12 at 17:15

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.