Jump to content

Recommended Posts

Posted

Hi,

I have a code to display the total number (count) of page under a certain template but i would like to display the count on some field.

The code i use for page count:

<?php
$countdemande = $page->count("template=v2-bs-demandes-recrutement, include=all"); {
 echo "$countdemande"; }
?>

Now i would like to do the same thing for some fields (options, checkboxes, radio) and display the number of time an option was selected.

ex.: Option field with multiple choice

  • option 1
  • option 2
  • option 3

How can i display the count (number of time this option was selected) of option 1 ?

Posted

Welcome to ProcessWire forums @Jee. Count is also available to fields:

$out = '';
$items = $pages->find('template=categories, limit=10');
foreach ($items as $i) {
 $out .= $i->title . '-' . $i->options_multi_field->count() . '<br>';
}
echo $out;

 

 

Posted

I actually thought you meant something different to @kongondo - who knows, but here goes, just in case:

$page->count("template=v2-bs-demandes-recrutement, optionsfieldname.label=option 1, include=all");

This will count the number of pages that has "option 1" selected in the "optionsfieldname" options field.

  • Like 1

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