Jump to content
Zeka

Custom page types, find and unpublished pages

Recommended Posts

Hi. 

I begin to rewrite hooks to custom pages types and have found out an issue with find method.

My custom PagesType class doesn't implement find method and inherits it from PagesType class. which relies on $pages->find 

By default $pages->find method exclude hidden and unpublished pages, but if I call find on my custom PagesType it returns also unpublished pages, but not hidden. 

In code:

class Posts extends PagesType
{

	public function __construct(ProcessWire $wire, $templates = array(), $parents = array())
	{
		parent::__construct($wire, $templates, $parents);
		$this->setWire($wire);
		$this->addTemplates("post"); // templates_id=51
		$this->addParents($this->pages->get("template=posts")->id); // parent_id=1036, 
		$this->setPageClass('Post');
	}
}

// in home.php

$news = wire('posts')->find('sort=-publish_from, limit=500'); 
// selectors => "sort=-publish_from, limit=500, parent_id=1036, templates_id=51"
// returns 489 items including unpublished pages, but excluding hidden pages


$news = wire('pages')->find('sort=-publish_from, limit=500, parent_id=1036, templates_id=51');
// selectors => "sort=-publish_from, limit=500, parent_id=1036, templates_id=51"
// returns 480 items excluding unpublished and hidden pages

Probably I missing something obvious, but I can't understand why it behaves in this way. In PagesClass::find I don't see anything that can affect on Pages::find. 

Maybe it's intended behavior with PagesType?

Thanks, Eugene. 

 

Share this post


Link to post
Share on other sites
3 hours ago, Zeka said:

In PagesClass::find I don't see anything that can affect on Pages::find.

This maybe?

if(!isset($options['findAll'])) $options['findAll'] = true;

https://processwire.com/api/ref/pages/find/

findAll (boolean): Find all pages with no exclusions, same as "include=all" option (default=false).

  • Thanks 1

Share this post


Link to post
Share on other sites

@Robin S This is terrible. I don’t know how I overlooked it, сause I've looked at this part so many times 

faecepalm.gif

Thanks!

  • Like 1

Share this post


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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...