Jump to content

Recommended Posts

Posted

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

 

Posted

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

 

Posted

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

Untested ;)

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

 

  • Like 1
  • Thanks 1
Posted (edited)
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
Posted
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

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
  • Recently Browsing   0 members

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