I have a List(text) field that can have multiple values. I am trying to create an entityQuery that returns nodes with specific items are checked within the field. The variable "availableServices" is an array of available services. I tried adding an andconditiongroup but that results in no items being returned. How do I check if a field has multiple values selected?
I've checked and when I search for items separately it returns values, but multiple items returns nothing. The nodes however have multiple items checked so it should return nodes.
if(isset($availableServices)) {
$and = $query->andConditionGroup();
foreach($availableServices as $service) {
$and->condition('field_available_services', $service);
}
$query->condition($and);
}
----Updated---
Basically I need to convert this into an entityquery:
SELECT "node_field_data"."created" AS "node_field_data_created", "node_field_data"."nid" AS "nid"
FROM
{node_field_data} "node_field_data"
INNER JOIN {node__field_available_services} "node__field_available_services_value_0" ON node_field_data.nid = node__field_available_services_value_0.entity_id AND node__field_available_services_value_0.field_available_services_value = 'Deposit-taking ATM'
INNER JOIN {node__field_available_services} "node__field_available_services_value_1" ON node_field_data.nid = node__field_available_services_value_1.entity_id AND node__field_available_services_value_1.field_available_services_value = 'Check Cashing'
INNER JOIN {node__field_location_type} "node__field_location_type" ON node_field_data.nid = node__field_location_type.entity_id AND node__field_location_type.deleted = '0'
WHERE ((node__field_location_type.field_location_type_value IN('Branch', 'ATM', 'Branch & ATM'))) AND (("node_field_data"."status" = '1') AND ("node_field_data"."type" IN ('branch_location')) AND (("node__field_available_services_value_0"."field_available_services_value" = 'Deposit-taking ATM') AND ("node__field_available_services_value_1"."field_available_services_value" = 'Check Cashing')))
ORDER BY "node_field_data_created" DESC