1. Home
  2. Snippets
  3. Calculate or display entry submissions count for a specific form

Calculate or display entry submissions count for a specific form

Heads up!

This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

Dismiss

The total number for form entries can be helpful if you want to display the number of users who participated in a survey or have entered a content. This number can easily calculated.

WPForms has a class specifically for handing entries and it contains many useful helper methods.

If you would like to fetch the total in PHP to display in your template or for further calculations, see the snippet below. Make sure and replace $form_id with the ID for the form.

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

If you would like to use this inside a post or page content, we can create a shortcode to access and display the entry count. The snippet below will create this shortcode.

/**
 * Shortcode that displays the number of completed entries for a form.
 *
 * Usage: [wpforms_entry_total form_id="X"] - X is the form ID.
 *
 * @param array $atts
 * @return int
 */
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' );
Updated on November 20, 2017

Was this article helpful?