jds43 Posted April 9, 2018 Share Posted April 9, 2018 Hello, I'm trying to select doctor pages associated with locations. Within this doctor page I have multiple pages selector (which are location pages) because doctors can work at many. When viewing a single location page, I'd like to loop through those doctors at that location, which is this $page. How can I achieve this because mine isn't working? $doctors = $pages->find('template=staff-page,parent=1018,locations=$page'); foreach($doctors as $doc) { echo "<h4>$doc->title</h4>"; } I guess I answered my own question. Is this an acceptable way to achieve? foreach($doctors as $doc) { foreach($doc->locations as $loc) { if($loc->title == $page->title) { echo "<h4>$doc->title</h4>"; echo "<h5>$loc->title</h5>"; } } } Link to comment Share on other sites More sharing options...
lokomotivan Posted April 9, 2018 Share Posted April 9, 2018 I think you just have to remove the parent=1018 from your selector, doctor page cant be child page of multiple locations... $doctors = $pages->find('template=staff-page,locations=$page'); foreach($doctors as $doc) { echo "<h4>$doc->title</h4>"; } Link to comment Share on other sites More sharing options...
jds43 Posted April 10, 2018 Author Share Posted April 10, 2018 I had to keep parent=1018 because I don't want to include staff-pages that aren't doctors. The $page selector below is drawing errors. $doctors = $pages->find('template=staff-page,locations=$page') This is working though. foreach($doctors as $doc) { foreach($doc->locations as $loc) { if($loc->title == $page->title) { echo "<h4>$doc->title</h4>"; echo "<h5>$loc->title</h5>"; } } } Link to comment Share on other sites More sharing options...
zoeck Posted April 10, 2018 Share Posted April 10, 2018 Untested $doctors = $pages->find("template=staff-page,parent=1018,locations={$page->id}"); 1 1 Link to comment Share on other sites More sharing options...
Robin S Posted April 10, 2018 Share Posted April 10, 2018 22 hours ago, devatgwl said: $doctors = $pages->find('template=staff-page,parent=1018,locations=$page'); In PHP you have to use double quotes if you want variables (i.e. $page) to be parsed inside a quoted string. See: http://php.net/manual/en/language.types.string.php#language.types.string.parsing $doctors = $pages->find("template=staff-page,parent=1018,locations=$page"); 1 Link to comment Share on other sites More sharing options...
jds43 Posted April 10, 2018 Author Share Posted April 10, 2018 (edited) 4 hours ago, zoeck said: Untested $doctors = $pages->find("template=staff-page,parent=1018,locations={$page->id}"); This worked too. Thank you! Edited April 10, 2018 by devatgwl Link to comment Share on other sites More sharing options...
jds43 Posted April 10, 2018 Author Share Posted April 10, 2018 16 minutes ago, Robin S said: In PHP you have to use double quotes if you want variables (i.e. $page) to be parsed inside a quoted string. See: http://php.net/manual/en/language.types.string.php#language.types.string.parsing $doctors = $pages->find("template=staff-page,parent=1018,locations=$page"); This is good to know, but I'm not getting anything from the selector. Link to comment Share on other sites More sharing options...
Robin S Posted April 10, 2018 Share Posted April 10, 2018 7 minutes ago, devatgwl said: This is good to know, but I'm not getting anything from the selector. This tells you that there are no published, non-hidden pages using template "staff-page" under parent with id "1018" with a field named "locations" containing the current page. Try removing parts of the selector to find out what part of it causes no pages to match the selector. If you are wanting to match hidden or unpublished pages see the docs here: https://processwire.com/api/selectors/#access_control 1 1 Link to comment Share on other sites More sharing options...
jds43 Posted April 10, 2018 Author Share Posted April 10, 2018 That did it Robin S. Thanks! 1 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