Advertisement
Guest User

Gravity Forms Counter

a guest
Feb 20th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. // http://pastebin.com/kHpaHQvi originally
  2. // http://www.gravityhelp.com/forums/topic/show-total-donations
  3. // usage: [guests form=01] where 1 is the form ID
  4. add_shortcode('guests', 'total_guests');
  5. function total_guests($atts) {
  6. $form_id = $atts['1'];
  7. // function to pull all the entries for one form
  8. $guests = RGFormsModel::get_leads($form_id);
  9. // start the total at zero
  10. $total = 0;
  11. // initialize a counter for the number of guests entries made
  12. $i = 0;
  13. // loop through all the returned results
  14. foreach ($guests as $amount) {
  15. // add each guests amount to the total
  16. // change 2 here to the field ID which holds the guests amount
  17. // the preg_replace will strip anything that is not a number or decimal
  18. $numeric_amount = preg_replace('/[^0-9\.]/Uis', '', $amount[2]);
  19. $total += $amount[2];
  20. // increment the counter so we know how many guest entries there are as well
  21. $i++;
  22. }
  23. // change this to your locale, or, if your locale is already defined, you can remove this line
  24. setlocale(LC_MONETARY, 'de_DE');
  25. // do some formatting and return the html output from the shortcode
  26. $output = "Nach bisherigem Stand haben " . ($total) . " Personen ihr Kommen zugesagt.";
  27. // just the string above will be returned. You can style it here or where you are using the shortcode
  28. return $output;
  29. }
  30. // needed for the above to process the guests list shortcode in sidebar widget
  31. add_filter('widget_text', 'do_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement