How to Display Entry Submissions Count for a Specific Form

Introduction

Would you like to display a count of total entries on your site for a specific form? The total number of form entries can be helpful if you want to display the number of users who participated in a survey or have entered a contest. This tutorial will show you how you can display your entry count using PHP.

Creating a shortcode

Creating a shortcode for this can be a lot easier if you’re planning on displaying this total in several places on your site and for several forms.

To use a shortcode, you need to first create it so it can be used on any page, post, or widget area on your site.

You’ll just need to add the following code snippet to your site.

If you need any help adding code snippets to your site, please review this tutorial.

/**
 * Shortcode that displays the number of completed entries for a form.
 *
 * Usage:  [wpforms_entry_total form_id="X"] - X is the form ID.
 *
 * @link   https://wpforms.com/developers/display-entry-submissions-count-for-a-specific-form/
 */

function wpf_dev_form_entry_total( $atts ) {

	$args = shortcode_atts( array(
        'form_id' => ''
    ), $atts );

    if ( empty( $atts[ 'form_id' ] ) ) {
    	return;
    }

    $total = wpforms()->entry->get_entries( array( 'form_id' => $atts[ 'form_id' ] ), true );

    return absint( $total );
}
add_shortcode( 'wpforms_entry_total', 'wpf_dev_form_entry_total' );

To use the shortcode, just add it to any post, page, or widget area on your site.

[wpforms_entry_total form_id="X"]

Just remember to replace the “X” with your own form ID. If you need assistance in finding your form ID, please view this article.

For our tutorial, we want to display how many children have signed up for our class so we will add the shortcode right in line with the text.

add the shortcode to your page inline with your text

Now when visitors see your page, they’ll see the total number of entries we have received for our form.

the visitors will see the display entry submissions count along with your form

Without using a shortcode

Alternatively, if you would like to fetch in the total of entries to display in your template or for further calculations, see the snippet below.

To apply the code to your form, replace $form_id with the ID for the form.

/**
 * PHP code snippet to fetch entry total inside PHP template.
 *
 * @link https://wpforms.com/developers/display-entry-submissions-count-for-a-specific-form/
 */

wpforms()->entry->get_entries( array( 'form_id' => $form_id ), true );

And that’s all you need in order to display your entry submission count on your WPForms. Would you like to create a shortcode to display your PayPal and Stripe transactions? Take a look at our tutorial on How to Display Table of PayPal/Stripe Transaction Details.