Jump to content
jds43

multiple pages selector and this page

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

 

Share this post


Link to post
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>";
}

 

Share this post


Link to post
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>";
        }		
    }							
}

Share this post


Link to post
Share on other sites

Untested ;)

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

 

  • Like 1
  • Thanks 1

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...