I'm building an entity query and I would like to check if one field contains one string or another. I'm building the query like so.
$searchname = 'test';
$searchtype' = 'type_1';
$query->condition('status', NODE_PUBLISHED);
$query->condition('field_type', $searchtype);
$query->sort('created','DESC');
However I'd like to check if field_type is either $searchtype or 'both' I attempted to do so using an orConditionGroup like so
$orCondition = $query->orConditionGroup();
$query->condition('status', NODE_PUBLISHED);
$orCondition->condition('status', NODE_PUBLISHED);
$query->condition('field_type', $searchtype);
$orCondition->condition('field_type','both');
$query->condition($orCondition);
$query->sort('created','DESC');
$nids = $query->execute();
However it acts like the orCondition isn't being considered at all. Using $orCondition it still does not produce nodes that have 'field_type' = 'both'. How would you go about checking whether a field contains one string or another in an entity query?
UPDATE: I added the field name to the or condition because I figured I would need to add it to both if I want it checked in both conditions. If there's a way around that, that'd be even better.
UPDATE 2: I made a second attempt using this code but I receive a 504 Timeout error when loading the page
$searchtype = 'test';
$query = \Drupal::entityQuery('node');
$conditionOne = $query->orConditionGroup();
$conditionTwo = $query->orConditionGroup();
$conditionOne->condition('status', NODE_PUBLISHED);
$conditionTwo->condition('status', NODE_PUBLISHED);
$conditionOne->condition('field_type', $searchtype);
$conditionTwo->condition('field_type','both');
$query->condition($conditionOne);
$query->condition($conditionTwo);
$query->sort('created', 'DESC');
$nids = $query->execute();
What I'm ultimately trying to accomplish is this logic
(status = true) AND (field_type = 'foo' or 'both')
where (status = 1 OR field_type = 'foo') AND (status = 1 OR field_type = 'both')
. Is that right or wrong?