# Fundraising Totals Shortcode (GiveWP)

> Adds a [wpide_give_totals] shortcode that shows the total raised and number of donations across all your GiveWP forms (or selected ones), for headers, impact pages and annual reports.

- Type: PHP
- Runs: Run everywhere
- Category: [Plugin Integrations](https://wpide.com/library/category/integrations/)
- Tags: givewp, donations, shortcode
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/give-fundraising-totals-shortcode/

## Code

```php
add_shortcode( 'wpide_give_totals', function ( $atts ) {
    if ( ! function_exists( 'give_get_meta' ) ) {
        return '';
    }

    $atts  = shortcode_atts( array( 'show' => 'amount', 'forms' => '' ), $atts, 'wpide_give_totals' );
    $ids   = array_filter( array_map( 'absint', explode( ',', $atts['forms'] ) ) );
    $key   = 'wpide_give_totals_' . md5( implode( ',', $ids ) );
    $total = get_transient( $key );

    if ( false === $total ) {
        if ( ! $ids ) {
            $ids = get_posts( array( 'post_type' => 'give_forms', 'post_status' => 'publish', 'numberposts' => -1, 'fields' => 'ids', 'no_found_rows' => true ) );
        }
        $total = array( 'amount' => 0.0, 'count' => 0 );
        foreach ( $ids as $form_id ) {
            $total['amount'] += (float) give_get_meta( $form_id, '_give_form_earnings', true );
            $total['count']  += (int) give_get_meta( $form_id, '_give_form_sales', true );
        }
        set_transient( $key, $total, HOUR_IN_SECONDS );
        $keys = (array) get_option( 'wpide_give_total_keys', array() );
        update_option( 'wpide_give_total_keys', array_unique( array_merge( $keys, array( $key ) ) ), false );
    }

    if ( 'count' === $atts['show'] ) {
        return esc_html( number_format_i18n( $total['count'] ) );
    }

    $amount = function_exists( 'give_currency_filter' ) && function_exists( 'give_format_amount' )
        ? give_currency_filter( give_format_amount( $total['amount'], array( 'sanitize' => false ) ) )
        : number_format_i18n( $total['amount'], 2 );

    return '<span class="wpide-give-total">' . wp_kses_post( $amount ) . '</span>';
} );

add_action( 'give_complete_donation', function () {
    foreach ( (array) get_option( 'wpide_give_total_keys', array() ) as $key ) {
        delete_transient( $key );
    }
} );
```

## Notes

Attributes: show="amount|count", forms="12,34" to limit to certain forms. Totals are cached for an hour and refresh after every completed donation.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Fundraising Totals Shortcode (GiveWP)" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
