I’m trying to filter related pages where the relationship is based on the content of a page selected in a page field.
The context is that I have a Review page which has a Place page linked via a Pages Field. The Place page has a structure field of locations which contains Districts. I’d like to return Reviews of places which have the same District (first matching is fine).
I can’t find a similar example in the docs or Filtering Compendium, so here’s my code (that’s not returning anything) which might help understand what I’m trying to do:
$place = $page->place()->toPage();
$district = $place->locations()->toStructure()->first()->district();
$moreDistrict = $kirby->collection('reviews')->filter(function ($child) use ($district){
if($child->place()->toPage()){
return $child->place()->toPage()->locations()->toStructure()->first()->district() === $district;
}
});