jacmaes 211 Posted Monday at 12:16 PM I'm working on a photographer's site. My tree is organized as such: Home --Photography ----Abstractions ------Photo 1 (photo on its own page; template: portfolio_image) ------Photo 2 ----Animals ----Signs ----etc. --Places: ----United States (template: country) ------New Jersey (template: state) --------Newark (template:city) --------Ringwood --------etc. ------New York In each photo's page (e.g. "Photo 1"), I have a page reference field name "city" where I can select the city (e.g. "Newark"). Now in "Places", I'm trying to retrieve all the photos in each country, for example all pics taken in the United States. I need to find the grandparent of "city", i.e. the country where that city belongs to, but "city.has_parent=$country" or "city.parent.parent=$country" don't work: <?php $foreach ($page->children as $country): $photos_by_country = $pages->find("template=portfolio_image, city.has_parent=$country"); foreach ($photos_by_country as $photos): echo $photos->title; endforeach; endforeach; ?> What's the selector for "the grandparent of the city field" is…? Thanks for your help. Share this post Link to post Share on other sites
bernhard 3,292 Posted Monday at 12:50 PM Dont know if that's the best option, but you could use two selectors: $cities = $pages->findIDs("template=city, parent=yourcity"); $photos = $pages->find([ 'template' => 'photo', 'city' => $cities, ]); Another option would be a saveReady hook that populates the country on each photo save. And I'm quite sure there are even better solutions 2 Share this post Link to post Share on other sites
jacmaes 211 Posted Monday at 01:24 PM Thanks a lot @bernhard. You put me on the right track. I just changed "parent=yourcity" to "has_parent=$country". For posterity, here are the two selectors in my case: $cities = $pages->findIDs("template=city, has_parent=$country"); $photos = $pages->find([ 'template' => 'portfolio_image', 'city' => $cities, ]); 1 Share this post Link to post Share on other sites
bernhard 3,292 Posted Monday at 01:27 PM You could also use sub-selectors: https://processwire.com/docs/selectors/#sub-selectors Share this post Link to post Share on other sites
jacmaes 211 Posted Monday at 01:28 PM That's why I tried first, but has_parent does not seem to work as a sub-selector. Share this post Link to post Share on other sites
bernhard 3,292 Posted Monday at 01:49 PM $photos = $pages->find("template=portfolio_image, city=[template=city, has_parent=$country]"); This does not work? Share this post Link to post Share on other sites
jacmaes 211 Posted Monday at 02:32 PM I've tried and double-checked, but no, for some reason, "has_parent" does not seem to work in this case, even if I manually replace $country with a valid parent id. "Parent" does work as expected, but it's of no use here. A bug, or a limitation with "has_parent" maybe? 1 Share this post Link to post Share on other sites