Jump to content

Count how many pages use a field?


OpenBayou
 Share

Recommended Posts

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");

 

  • Like 3
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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!=''");

 

 

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