Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to have query with EntityFieldQuery that return me nodes with title start with A or B but has not obvious method to use or in property condition, I dont want use db_select or db_query. in this link not comes like but it work ,but If I want use REGEX operator it return me error.

  $query=new EntityFieldQuery();
        $query->entityCondition('entity_type', 'node')
        ->entityCondition('bundle', 'product_display')
        ->propertyCondition('status', 1);
$query->propertyCondition('title', '^(B|A)','REGEX');              
share|improve this question
up vote 2 down vote accepted

The reason it doesn't work is because there's no REGEX operator in MySQL.

You probably meant REGEXP, which does work in an EntityFieldQuery.

share|improve this answer

There is no database agnostic support for regex in EntityFieldQuery. The documentation in EntityFieldQuery::propertyConditon lists the available operators. As mentioned by Clive, this list is not complete. Apparently you can use any operator that is supported by your database backend.

As an alternative that should be supported across different database backends, you could build multiple queries using the STARTS_WITH operator and then merge the results.

Or you write a custom query using db_query. Or use db_select with or-linked conditions.

share|improve this answer
I told in question ,I dont want use db_select or db_query, really is not clear way to using or in EntityFieldQuery ?? – zhilevan Feb 3 '14 at 13:16
No, you didn't write that in the question. I just told you, that what you want is not possible with EntityFieldQuery, at least not for propertyConditions. – berliner Feb 3 '14 at 13:19
@zhilevan You probably saw this thread already? It explains an alternative using tags. – berliner Feb 3 '14 at 13:20
@berliner I have one parameter in my codes that I want use it in myCondition,how can I pass my parameter to addTag function ? – zhilevan Feb 3 '14 at 13:25
This isn't right actually, EntityFieldQuery transparently supports any valid MySQL operator – Clive Feb 3 '14 at 13:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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