Jee Posted November 5, 2016 Share Posted November 5, 2016 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 ? Link to comment Share on other sites More sharing options...
kongondo Posted November 5, 2016 Share Posted November 5, 2016 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; Link to comment Share on other sites More sharing options...
adrian Posted November 5, 2016 Share Posted November 5, 2016 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. 1 Link to comment Share on other sites More sharing options...
Jee Posted November 6, 2016 Author Share Posted November 6, 2016 Thanks Guys! Link to comment Share on other sites More sharing options...
arjen Posted November 6, 2016 Share Posted November 6, 2016 When you need a simple count is it preferred to use: count("selector") versus $pages->find("selector")->count() since count("selector") method is way faster. 4 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