Jump to content

Selector "children.count" includes unpublished pages.


Tom.
 Share

Recommended Posts

I can confirm that children.count returns all children - including unpublished and hidden ones. 
At least in my current project.

Maybe it's similar to this:

A work-around... not yet.

You could try to find out if those child pages are viewable or something like this.

  • Like 1
Link to comment
Share on other sites

I think this is by design to optimize queries. But not sure. It uses COUNT in SQL to evaluate children counts which don't check for page status, I can imagine on very large sets it could get slow?

Anyway this case is rare you really need this and have access aware. What is your use case exactly? 

You can always just loop the pages in question and check for $page->numChildren(true) which is access aware. (You could also store/cache that info in a real field on the page with some hooks and use that.)

Some example with numChildren()

$res = $pages->find("template=basic-page");

foreach($res as $r){
	$r->has_children = $r->numChildren(true) > 1 ? "true" : "false" ;
}

echo " | has children: " . $res->find("has_children=true");
echo " | no children: " . $res->find("has_children=false");

 

  • Like 2
Link to comment
Share on other sites

Hi @Soma

It's for an internal project management system I'm working on. There are categories that let you know how many projects belong to that system. Archiving a project sets it to unpublished. However, it still shows as it exists in the count. 

I'm planning on finishing my eCommerce system I'm building for ProcessWire soon and that also will suffer if it has a count of the amount of products in each category. 

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