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/show-total-donations
- // usage: [guests form=01] where 1 is the form ID
- add_shortcode('guests', 'total_guests');
- function total_guests($atts) {
- $form_id = $atts['1'];
- // function to pull all the entries for one form
- $guests = RGFormsModel::get_leads($form_id);
- // start the total at zero
- $total = 0;
- // initialize a counter for the number of guests entries made
- $i = 0;
- // loop through all the returned results
- foreach ($guests as $amount) {
- // add each guests amount to the total
- // change 2 here to the field ID which holds the guests amount
- // the preg_replace will strip anything that is not a number or decimal
- $numeric_amount = preg_replace('/[^0-9\.]/Uis', '', $amount[2]);
- $total += $amount[2];
- // increment the counter so we know how many guest entries there are as well
- $i++;
- }
- // change this to your locale, or, if your locale is already defined, you can remove this line
- setlocale(LC_MONETARY, 'de_DE');
- // do some formatting and return the html output from the shortcode
- $output = "Nach bisherigem Stand haben " . ($total) . " Personen ihr Kommen zugesagt.";
- // 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