// http://pastebin.com/kHpaHQvi originally // http://www.gravityhelp.com/forums/topic/show-total-donations // usage: [donations form=37] where 37 is the form ID add_shortcode('donations', 'total_donations'); function total_donations($atts) { $form_id = $atts['form']; // function to pull all the entries for one form $donations = RGFormsModel::get_leads($form_id); // start the total at zero $total = 0; // initialize a counter for the number of donations made $i = 0; // loop through all the returned results foreach ($donations as $amount) { // add each donation amount to the total // change 3 here to the field ID which holds the donation amount $total += $amount[3]; // increment the counter so we know how many donations 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, 'en_GB'); // do some formatting and return the html output from the shortcode $output = "We have raised " . money_format('%i', $total) . " from $i donors."; // 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 donation shortcode in sidebar widget add_filter('widget_text', 'do_shortcode');