1

Is this the correct way to add field Conditions

$query->entityCondition('entity_type', 'profile2')
   ->entityCondition('bundle', 'user_profile')
   ->fieldCondition('field_town_city', 'value', "%".$search_title."%", 'LIKE')
   ->fieldCondition('field_land_state', 'value', "%".$search_title."%", 'LIKE');

1 Answer 1

3

You can chain multiple field conditions, however I'd probably try something like this (haven't tested it):

->fieldCondition('field_town_city', 'value', $search_title, 'CONTAINS')

The EntityFieldQuery::fieldCondition() invokes the addFieldCondition() method, see the possible $op values on api.drupal.org:

https://api.drupal.org/api/drupal/includes!entity.inc/function/EntityFieldQuery%3A%3AaddFieldCondition/7

5
  • can you give a example code?
    – Mukilan R
    Sep 5, 2014 at 10:22
  • 1
    @Mukil What do you need example code for exactly? Your code is correct
    – Clive
    Sep 5, 2014 at 10:22
  • when i execute this code $query->entityCondition('entity_type', 'profile2') ->entityCondition('bundle', array('user_profile'), IN) ->fieldCondition('field_fl_name', 'value', $search_title, 'CONTAINS') ->fieldCondition('field_town_city', 'value', $search_title, 'CONTAINS'); it returns empty array.
    – Mukilan R
    Sep 5, 2014 at 10:27
  • how to add OR condition between fieldCondition...?
    – Mukilan R
    Sep 5, 2014 at 10:29
  • @Mukil As far as I know there's no CONTAINS in MySQL. OP might be thinking of T-SQL. Just use LIKE if your db engine doesn't support it. ORs are tricky with EFQ, see drupal.stackexchange.com/questions/14499/…
    – Clive
    Sep 5, 2014 at 10:33

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.