OpenBayou Posted January 21, 2017 Posted January 21, 2017 Is there a way to show how many pages are using the 'title' field? I tried doing '$page->count' and 'ceil' with no results.
Harmen Posted January 21, 2017 Posted January 21, 2017 I think you can do it this way: $pages = wire("pages"); $i=0; foreach ($pages as $page){ if $page->hasField("title"){ $i++; } } return $i;
OpenBayou Posted January 21, 2017 Author Posted January 21, 2017 Error: Call to a member function hasField() on a non-object
Robin S Posted January 21, 2017 Posted January 21, 2017 Try: $template_has_title = $fields->get('title')->getFieldgroups()->implode('|', 'name'); $page_has_title = $pages->find("template=$template_has_title, has_parent!=2"); If you just want the count of the pages rather than the pages themselves you can do: $count = $pages->count("template=$template_has_title, has_parent!=2"); 3
OpenBayou Posted January 21, 2017 Author Posted January 21, 2017 29 minutes ago, Robin S said: Try: $template_has_title = $fields->get('title')->getFieldgroups()->implode('|', 'name'); $page_has_title = $pages->find("template=$template_has_title, has_parent!=2"); If you just want the count of the pages rather than the pages themselves you can do: $count = $pages->count("template=$template_has_title, has_parent!=2"); The above works but it checks if a page is using the field. How do I check for pages that use the field and ignore those that are blank?
Harmen Posted January 21, 2017 Posted January 21, 2017 1 hour ago, OpenBayou said: How do I check for pages that use the field and ignore those that are blank? Add an if statement for the field where the value of the field is blank.
LostKobrakai Posted January 21, 2017 Posted January 21, 2017 2 hours ago, Harmen said: Add an if statement for the field where the value of the field is blank. Or rather not do that, because it would mean uselessly loading pages. $count = $pages->count("template=$template_has_title, has_parent!=2, title!=''"); 3
Robin S Posted January 21, 2017 Posted January 21, 2017 If you want pages where a field is not empty you don't need to deal with the fieldsets/templates at all. Just: $count = $pages->count("title!='', has_parent!=2"); 2
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