Jump to content

Using owner selector to determine if the owner page is published


a-ok
 Share

Recommended Posts

I'm trying to be smart and use the `owner` selector.

I'm using a repeater `projects_awards` on a `projects` template that has about 20-30 pages and want to retrieve all the repeater rows on a separate page `About`.
I could either query all the projects, that have `projects_awards.count>0` then loop through those but that doesn't seem very efficient. I could just query the repeater template `template=repeater_projects_awards` but then that would return the rows even if the page it is on (owner) is unpublished. You see my dilemma.

I thought this could work...

template=repeater_projects_awards, projects_awards.owner.status!=2049, include=all

But returns empty – am I using this correctly?

Link to comment
Share on other sites

For what I understand, the owners elector will try to get the pages where the projects_awards is set, not the actual repeater pages, I'm thinking the template selector is what's causing the error because the template repeater_projects_awards doesn't have a projects_awards field. (but my reasoning could be messed up too haha). I'd try something like this maybe, that would give an array with a PageArray in each item, though you might to flatten the array and have all repeater pages in a single array:

$awards = $pages->find('template=projects, projects_awards.count>0')->explode('projects_awards');

 

Link to comment
Share on other sites

1 hour ago, a-ok said:

template=repeater_projects_awards, projects_awards.owner.status!=2049, include=all

 

I guess that should be 2048: http://cheatsheet.processwire.com/page/page-status/page-statusunpublished-2048/

1 hour ago, a-ok said:

but then that would return the rows even if the page it is on (owner) is unpublished.

Sure about that? I thought you only get unpublished pages with find() if you add include=all to the selector.

Link to comment
Share on other sites

10 hours ago, a-ok said:

template=repeater_projects_awards, projects_awards.owner.status!=2049, include=all

The status flags are bitwise so if you use a flag value directly to find published pages it would need to be like this:

projects_awards.owner.status<2048

But for PageFinder selectors you can use a string for status:

projects_awards.owner.status!=unpublished

You would also want to exclude unpublished repeater pages because otherwise you can get unfilled "ready" repeater pages in your result. So your selector would be:

template=repeater_projects_awards, projects_awards.owner.status!=unpublished, status!=unpublished, include=all

 

  • Like 2
Link to comment
Share on other sites

8 hours ago, Robin S said:

The status flags are bitwise so if you use a flag value directly to find published pages it would need to be like this:


projects_awards.owner.status<2048

But for PageFinder selectors you can use a string for status:


projects_awards.owner.status!=unpublished

You would also want to exclude unpublished repeater pages because otherwise you can get unfilled "ready" repeater pages in your result. So your selector would be:


template=repeater_projects_awards, projects_awards.owner.status!=unpublished, status!=unpublished, include=all

  

This is amazing. PW is so so so good. Much appreciated, @Robin S and the others ?

  • 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

  • Recently Browsing   0 members

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