Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Help Scout 52777
- // shortcode to grab dinner selection totals from one form by value
- // usage: [dinner choice='whatever' formid=ID]
- // eg [dinner choice='Panko Cod' formid=892]
- if (!function_exists('ch_get_dinners')) {
- function ch_get_dinners($atts) {
- // parse the shortcode
- extract(shortcode_atts(array(
- 'choice' => null,
- 'formid' => null
- ), $atts));
- // define constants
- $paging = array('offset' => 0, 'page_size' => 100 );
- $sorting = array();
- $total_count = 0;
- // define search criteria
- $search_criteria = array();
- $search_criteria["field_filters"][] = array('value' => $choice);
- // get the entries which match the dinner choice
- $entries = GFAPI::get_entries($formid, $search_criteria, $sorting, $paging, $total_count);
- // initialize the counter
- $counter = 0;
- // define which fields to check for dinner selections
- $all_fields = array(22, 24, 52, 61, 66);
- // loop through all the entries
- foreach($entries as &$entry){
- // check our 5 possible fields
- foreach ($all_fields as &$field_id){
- if ($entry[$field_id] == $choice){
- $counter++;
- }
- }
- }
- return $counter;
- }
- }
- add_shortcode('dinner', 'ch_get_dinners');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement