tof
September 5, 2019, 11:42am
1
Hi, I’m looking for the correct syntax about filter in a endpoint/php call, in order for a specific filter item to accept several values.
Here I have a working piece of code that works to retrieve “events” for which “type ” = ‘workshop’
$eventstocome = cockpit("collections")->find("events", ['filter' => ['published'=> true, 'ended'=> false, 'type' => 'workshop'],'limit'=> 100, 'sort'=>['startdate'=> 1] ]);
But I would like to retrieve “events” that match “type ” either ‘workshop’ or ‘spectacle’ or ‘lecture’.
Is there any syntax with “OR” or something like “in_array” that would make it feasible ?
Thanks for your help.
artur
September 5, 2019, 2:12pm
2
$eventstocome = cockpit("collections")->find("events", [
'filter' => [
'published'=> true,
'ended'=> false,
'$or' => [
['type' => 'workshop'],
['type' => 'spectacle'],
['type' => 'lecture'],
]
],
'limit'=> 100,
'sort'=>['startdate'=> 1]
]);
OR
$eventstocome = cockpit("collections")->find("events", [
'filter' => [
'published'=> true,
'ended'=> false,
'type' => ['$in' => ['workshop', 'spectacle', 'lecture']]
],
'limit'=> 100,
'sort'=>['startdate'=> 1]
]);
tof
September 5, 2019, 10:49pm
3
Many thanks Artur, it’s exactly what I was looking for !
I’ve seen these operators $or and $in in my searches but always related to json API, and I did not managed to get the exact syntax for php.
And thanks again for the quick answer.