1

I need to make a query where the same filed must have one value OR another. Basically:

->fieldCondition($field_example, 'tid', (array) $var1) ... OR
->fieldCondition($field_example, 'tid', (array) $var2)

Already saw some examples using TAG but I really don't understand how it's done. In alternative, can I use dbquery? Or should I avoid it?

Thanks!

1

You should be able to use db_or(), something like this:

$or = db_or()
  ->fieldCondition($field_example, 'tid', (array) $var1)
  ->fieldCondition($field_example, 'tid', (array) $var2);
$query->condition($or);

More info here.

1

Thanks m1n0. I want to add that condition but I already have other in my query:

$query = new EntityFieldQuery();

$query
  ->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'content_x')
  ->propertyCondition('status', 1)
  ->fieldOrderBy('field_date', 'value', 'DESC')
  ->fieldCondition('field_division', 'tid', (array) $division)
  ...
  The OR condition here...
  ...
  ->range(0, 5)
  ->addMetaData('account', user_load(1));

$result = $query->execute();

So, I need not just the OR but to have the code I already had and the OR. In the link you sent me there is another way to do it but I tried without success...

0

In EFQ, db_or() is not possible to add. So both the top answers are wrong!

By adding a TAG to the query and later altering it seems to be the best possible way. However I've found that using basic db_select instead of EFQ for those cases serves me good.

But who wants to add OR to EFQ: Using OR with EntityFieldQuery

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.