Jump to content

Recommended Posts

Posted

I think you can do it this way:

$pages = wire("pages");
$i=0;
foreach ($pages as $page){
	if $page->hasField("title"){
		$i++;
	}
}
return $i;

 

Posted

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
Posted
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?

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

Posted
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
Posted

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

 

  • Like 2

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