Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://pastebin.com/kHpaHQvi originally
- // http://www.gravityhelp.com/forums/topic/counter
- // usage: [guests form=1] where 1 is the form ID
- // from http://www.gravityhelp.com/forums/topic/counter#post-154024
- add_shortcode('guests', 'total_guests');
- function total_guests($atts) {
- $form_id = $atts['form'];
- // function to pull all the entries for one form
- // Chris Hajer April 15, 2014 to return more than 30 entries (the default)
- $guests = RGFormsModel::get_leads($form_id, 0, 'ASC', '', 0, 999, NULL, NULL, FALSE, NULL, NULL, 'active', FALSE);
- // start the totals at zero
- $adults = 0;
- // initialize a counter for the number of guests entries made
- $i = 0;
- // loop through all the returned results
- foreach ($guests as $amount) {
- // total the adults
- // change 3 here to the Field ID which holds the number of adults
- $adults += $amount[3];
- // increment the counter so we know how many total guests there are
- $i++; // we may not need to use this
- }
- // do some formatting and return the output from the shortcode
- $output = "$adults";
- // just the string above will be returned.
- // You can style it here or where you are using the shortcode
- return $output;
- }
- // needed for the above to process the guests list shortcode in sidebar widget
- add_filter('widget_text', 'do_shortcode');
- // shortcode to grab dinner selection totals from one form by value
- // usage: [dinner choice='whatever' formid=ID]
- // eg [dinner choice='Panko Cod' formid=4]
- 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["status"] = "active";
- $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, based on Field ID
- $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