I'm trying to query some nodes by a given string checking if the string is either in the node title OR if the string is an exact match of concatenating the value of two strings.

I know this should be possible in normal mysql but not sure it can be translated in an entity query. Has anyone stumbled upon this problem before?

Is there some sort of 'free text' condition which is not tied up to fields.

At the moment the below code complains about the fact that CONCAT_WS(...) is not a field which is true.

Maybe there is a simpler solution to this but I'm just not seeing it.

$query = \Drupal::entityQuery('node')
        ->condition('status', 1)
        ->condition('type', 'CONTENT_TYPE');

$group = $query->orConditionGroup()
        ->condition('title', $string , 'CONTAINS')
        ->condition("CONCAT_WS('',FIELD_1,FIELD_2)", $string);

$nids = $query->execute();

1 Answer 1


I don't think it's possible this way. I would rather split the $string in two parts, and check the two fields with each part.

$query->condition("FIELD_1)", $string_1);
$query->condition("FIELD_2)", $string_2);

You have many ways to separate the string in two. Is this helping you ?

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.