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
- $guests = RGFormsModel::get_leads($form_id);
- // start the totals at zero
- $adults = 0;
- $children = 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 2 here to the field ID which holds the number of adults
- $adults += $amount[2];
- // total the children
- // change 5 here to the field ID which holds the number of children
- $children += $amount[5];
- // increment the counter so we know how many total guess there are
- $i++; // we may not need to use this
- }
- // do some formatting and return the output from the shortcode
- $output = "So far $adults adults and $children kids are attending the wedding";
- // 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');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement