I pasted the snippet into my functions.php, did a little customizing and set up the counter here: http://www.doro-und-nick.de/test/
The counter displays, but does not show entries from the guest list form (form ID 1). The form is located here: http://www.doro-und-nick.de/gaesteliste/, Field-ID 2 asks for the number of guests (actually the frontend choices are "1+1", "1+2" and so on, but the backend values in the form are straight numbers like 2, 3 etc.).
This is your code after my customizing:
// http://pastebin.com/kHpaHQvi originally
// http://www.gravityhelp.com/forums/topic/show-total-donations
// usage: [gaesteliste form=01] where 37 is the form ID
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 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 guest attending to the total
// change 2 here to the field ID which holds the amount of atteding guests
$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 " . money_format('%i', $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');
1. Any suggestions why the form entries are not shown/added?
2. How do I have to change the following line to only show the total number of guests without decimal places and currency? Sry, keep getting errors if i start changing it on my own..
$output = "Nach bisherigem Stand haben " . money_format('%i', $total) . " Personen ihr Kommen zugesagt.";
Posted 11 years ago on Tuesday February 19, 2013 |
Permalink