I thought I had the code for this figured out, but this isn’t behaving the way it ought to. (It isn’t returning any results, when it should match a page.) Can someone help me troubleshoot?
$activity = "Hiking"; /* for example */
$calendar = $all_calendarItems->filter(function ($p) use ($activity) {
return in_array(
$activity,
$p
->facts() /* facts is an object field */
->toObject()
->activity() /* activity is a multiselect field */
->split()
);
});
Ok, and what do you get when you dump($calendar)? Note that the code should work fine, provided that a) the field names (facts and subfield activity are correct, b) $ $all_calendarItems is a pages collection. Maybe post what is stored in one of the content files you are filtering..
Argh! While preparing another sample set of data to post here, I realized the issue resulted from a separate issue in the logic of this page’s controller. I should have realized that earlier, since I don’t trust myself with this complex filtering, I assumed that was the culprit. I’m all good now, and as you confirmed, the code I posted initially does work as intended. Thanks for your help.