hezmann Posted January 15, 2018 Share Posted January 15, 2018 Hi All, Just recently started with ProcessWire and coming along ok but am struggling with figuring out how to get pages based on values of fields in children of children. What I have is a structure like this... Walks Walk Variations Walk Segments Walk Segments has two page reference fields (to Walk Towns) Start Town and End Town. Walk Towns has a Maps Marker field which I've added the field Continent to. What I'm trying to get is a list of all walks that are in a particular continent. Any help would be most appreciated! Heather Link to comment Share on other sites More sharing options...
OLSA Posted January 16, 2018 Share Posted January 16, 2018 Hello. Dont know if I understand you well, but maybe this: // get childrens what are in desired continent $europe_walks = $pages->find('template=walk-segments, start_town.continent.title="Europe"'); // or can use selector with continent page id eg. "start_town.continent=10050" $variations = array(); // can use this inside foreach to store page arrays id foreach($europe_walks as $variation){ echo $variation->title . "<br>"; //Walk Segments echo $variation->parent->title . "<br>";//Walk Variation echo $variation->parent->parent->title . "<br>";//Walks } Second option can be this: //directly get walk variations $europe_walks = $pages->find('template=walk-variations, children.start_town.continent.title="Europe"'); Regards. Link to comment Share on other sites More sharing options...
Robin S Posted January 16, 2018 Share Posted January 16, 2018 1 hour ago, hezmann said: Walk Towns has a Maps Marker field which I've added the field Continent to. Not quite sure what you mean here. You somehow edited the Map Marker fieldtype to include a continent subfield? Or do you just mean you added a field Continent to the Walk Towns template? It might depend a bit on what type of field Continent is, but something like this should work: $walks_in_africa = $pages->find("template=walk, (children.children.start_town.continent=Africa), (children.children.end_town.continent=Africa)"); 1 Link to comment Share on other sites More sharing options...
hezmann Posted January 16, 2018 Author Share Posted January 16, 2018 I actually added some extra fields (state, region, country, continent) to the module so the geocode grabs those for me from Google (well, technically I'm looking up the continent from a table with all countries/continents because Google doesn't provide that) so it would be refered to as (assuming the Maps Marker field is named marker) marker.continent. I'll give the suggestions a go - Thanks! 1 Link to comment Share on other sites More sharing options...
Robin S Posted January 16, 2018 Share Posted January 16, 2018 13 minutes ago, hezmann said: I actually added some extra fields (state, region, country, continent) to the module so the geocode grabs those for me from Google Sounds very useful. Please share your module fork when you're ready. Link to comment Share on other sites More sharing options...
hezmann Posted January 16, 2018 Author Share Posted January 16, 2018 Will try to remember to do that. Need to clean the code up some first. Thanks @Olsa Link to comment Share on other sites More sharing options...
hezmann Posted January 16, 2018 Author Share Posted January 16, 2018 Sorry about that - hit enter and it submitted then couldn't edit. What I meant to say was... Will try to remember to do that. Need to clean the code up some first. Thanks @Olsa and @Robin S. I was able to get what I needed with... $walk_segments = $pages->find('template=walk_segments, start_town.marker.continent.title="Europe"'); foreach($walks_segments a as $thewalk){ echo $thewalk->parent->parent->title; } I just need to catch duplicates now but that should be easy enough! Link to comment Share on other sites More sharing options...
Robin S Posted January 16, 2018 Share Posted January 16, 2018 5 minutes ago, hezmann said: I was able to get what I needed with... $walk_segments = $pages->find('template=walk_segments, start_town.marker.continent.title="Europe"'); foreach($walks_segments a as $thewalk){ echo $thewalk->parent->parent->title; } I just need to catch duplicates now but that should be easy enough! Glad you have it working. Just a couple of things to be aware of if you do it this way: 1. Depending on how many Walk Variations are within a Walk, and how many Walk Segments are within a Walk Variation, you could end up loading way more pages into memory than you actually need (you only need the Walk pages). But if the number of pages isn't large then this could be fine. 2. If there are a lot of Walks in the continent, and for efficiency you want to paginate them into groups of 20 for example, this becomes difficult. Because you don't know how many Walks will result from any set of Walk Segments until you loop over them. 1 Link to comment Share on other sites More sharing options...
OLSA Posted January 16, 2018 Share Posted January 16, 2018 @hezmann 40 minutes ago, hezmann said: Thanks @Olsa and @Robin S. I was able to get what I needed with... $walk_segments = $pages->find('template=walk_segments, start_town.marker.continent.title="Europe"'); foreach($walks_segments a as $thewalk){ echo $thewalk->parent->parent->title; } If this works for you, than I mean that also you can try this example what is in basic the same what Robin S write in first answer: //please note template in selector, in this case go from top to bottom $walk_segments = $pages->find('template=walks, children.children.start_town.marker.continent.title="Europe"'); foreach($walks_segments a as $thewalk){ echo $thewalk->title; } Link to comment Share on other sites More sharing options...
hezmann Posted January 16, 2018 Author Share Posted January 16, 2018 That's perfect @OLSA.!!! Thanks!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now