Basically I want to have a field called locations and then the value would be one of say 5 different locations. The user will then filter these locations using checkboxes. I have it working with a selectbox and choosing one value but I now need it to filter multiple options at once.
So when the page is reloaded it can show all pages with locationA, locationB or location.
The documentation doesn’t seem too clear for the custom filters though as I did look at that earlier.
// $selections is an array with the values of the selected checkboxes, don't know how you retrieve them in your setup
// $selections = array('locationA', 'locationB', 'location');
$stores = $pages->filter(function($child) {
// only $child that return true in here will be part of $stores
return in_array($child->locations(), $selections);
});
$selections = array('locationA', 'locationB', 'location');
$stores = $pages->filter(function($child) {
// only $child that return true in here will be part of $stores
return in_array($child->locations(), $selections);
});
as $selections is an array declared outside the scope of the function
$selections = array('locationA', 'locationB', 'location');
$stores = $pages->filter(function($child) use($selections) {
// only $child that return true in here will be part of $stores
return in_array($child->locations(), $selections);
});
@lukasbestle, ok, it does work even without the cloning, but only if you return the results within a nested foreach loop, i.e. your solution does not return a collection you can use in a controller, like the custom filter does.
Hi,
and how does it work if I have really different fields?
Here you filter by the field “location“ if i understand it right. But if I have the fields “zip“ and “location“ as example.
How can I link it together?