I'm using this code to show the total donations made on a site using Gravity Forms. But how to limit to only show donations made by logged in user? Yes, the user has made several donations.

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 [49] here to the field ID which holds the donation amount
            // the preg_replace will strip anything that is not a number or decimal

            $numeric_amount =  preg_replace('/[^0-9\.]/Uis', '',$amount[49]);
            $total += $numeric_amount;
            // increment the counter so we know how many donations there are as well

    // do some formatting and return the html output from the shortcode
    $output = "We have raised $" . $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;
add_filter('widget_text', 'do_shortcode');
  • This question cannot be answered without intimate knowledge of the plugin in question, and as such would be best addressed in the plugin's official support channels.
    – bosco
    Apr 3, 2017 at 8:01

1 Answer 1


Answer came from a plugin. gravitywp-count.

Not the answer you're looking for? Browse other questions tagged or ask your own question.