Jump to content

Page selector referencing template of pages in a page field


snck
 Share

Recommended Posts

Hi there,

I have a problem constructing a selector that finds all pages that refer to pages with a specific template.

I have pages using an event template and I want to show events based on a specific context. In this example I want to filter the results and only show event pages that relate to a specific template (exhibitions) in their page field related_pages.

What I tried:

$events = $pages->find("template=event, related_pages.template.name=exhibition");

Unfortunately it does not work (0 results).

Same with this:

$events = $pages->find("template=event, related_pages=[template.name=exhibition]");

At the moment I am helping myself with the following lines, but I have a strong feeling that there is a more efficient solution:

$events = $pages->find("template=event");

foreach($events as $event){
  if(!count($event->related_pages->find("template=exhibition"))){
  	$events->remove($event);
  }
}

 

I really hope that one of you can help me out.

Thanks in advance!

Flo

Link to comment
Share on other sites

7 hours ago, snck said:

What I tried:


$events = $pages->find("template=event, related_pages.template.name=exhibition");

Unfortunately it does not work (0 results).

Works fine for me. ProcessWire 3.0.153 dev 

  • Thanks 1
Link to comment
Share on other sites

4 hours ago, kongondo said:

Works fine for me. ProcessWire 3.0.153 dev 

Strange... Could it have something to do with the fact that related_pages (in my case) takes multiple pages? 

Link to comment
Share on other sites

Please check status and/ or permission

$events = $pages->find("template=event, related_pages.template.name=exhibition,include=all,check_access=0");
  • include=hidden
  • include=unpublished
  • include=all

Check if your template is accessible via API if it is not viewable for the current user!

  • Like 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

×
×
  • Create New...