Tom. Posted July 16, 2018 Share Posted July 16, 2018 From what I can tell the selector children.count includes unpublished pages. However, I'm unsure if this is intended functionality? If it is, is there a way around it? Link to comment Share on other sites More sharing options...
wbmnfktr Posted July 16, 2018 Share Posted July 16, 2018 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. 1 Link to comment Share on other sites More sharing options...
Soma Posted July 16, 2018 Share Posted July 16, 2018 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"); 2 Link to comment Share on other sites More sharing options...
Tom. Posted July 17, 2018 Author Share Posted July 17, 2018 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. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now