Jump to content

multiple pages selector and this page


jds43
 Share

Recommended Posts

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

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

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

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");

 

  • Like 1
Link to comment
Share on other sites

4 hours ago, zoeck said:

Untested ;)


$doctors = $pages->find("template=staff-page,parent=1018,locations={$page->id}");

 

This worked too. Thank you!

Edited by devatgwl
Link to comment
Share on other sites

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

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

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...