Shortcode: Display Number of Entries Submitted
Extends the [gravityforms] shortcode, providing a custom action to retrieve the total entry count for a given form. Also supports retrieving entry counts by entry status (i.e. “trash”, “spam”, “unread”, “starred”).
Are you limiting how many entries can be submitted and looking for a way to display the number of entries left? We’ve got a shortcode for that too!
After installing this snippet, you will be able to display the number of form entries that have been submitted with the following shortcode:
[gravityforms action="entry_count" id="your_form_id"]
Getting Started
Check requirements
- Make sure you have Gravity Forms installed and activated.
- Already have a license? Download Latest Gravity Forms
- Need a license? Buy Gravity Forms
- Make sure you have Gravity Forms installed and activated.
Install the snippet
- Copy and paste the entire snippet into your theme’s functions.php file.
Configure the shortcode
- For the basic version just enter your form id and the shortcode will return the total number of submitted entries!
- If you would like to have a little more control over the type of entry being pulled, read on for some additional configuration options.
- View available shortcode attributes
Usage Examples
Basic Usage
[gravityforms action="entry_count" id="your_form_id"]
[gravityforms action="entry_count" id="2"]
Would you like to use this shortcode in the sidebar of your website? Check out the Shortcode Widget plugin.
Unread Entries, Comma Format
[gravityforms action="entry_count" id="2" status="unread" format="comma"]
Display the entry count for unread entries using comma format (i.e. “1,001”).
Trashed Entries, Decimal Format
[gravityforms action="entry_count" id="2" status="trash" format="decimal"]
Display entry count for entries in the trash using decimal format (i.e. “1.001”)
Shortcode Attributes
id (int) (required)
The ID of your form. Defaults to false.
status (string) (optional)
The entry status type that you would like to display number of entries submitted for. Defaults to “total.” Options include: “total”, “unread”, “starred”, “trash”, and “spam”.
format (string) (optional)
The type of formatting to be used when displaying the entry count. Defaults to false. Options include: “comma” and “decimal”.
How’d we do?
If you use it and like it, let us know. We’d love to hear the different ways you found this code useful!
Learn more about Gravity Forms Shortcodes
Our Complete Guide to Gravity Forms Shortcodes will show you each type of shortcode available for Gravity Forms, how to set them up, as well as how to fine tune parameters to customize which form data is displayed on your pages.
Is there a way to count how far “down” an entry is. For example, building a waitlist, I want to know what position a entry is, are they 10th in line, 20th in line. I was thinking I could get the entryID of the first one and then subtract the the differences of everything. However, entryIDs are not in order. Meaning if I create another entry in another form and then add a new one to this form, it is not sequential. Plus if you use random entryIDs, then it all goes out the door.
Hi,
You can use our GP Unique ID Perk to generate sequential IDs that will be specific to the entries of a form. This should work better for what you’re trying to do.
Best,
Hello! and how do I set the counter to “0” again?
Can it be reset or is that not possible?
Thanks
Hi Paolo,
This snippet counts how many entries were submitted. If you need to tweak the snippet you can get in touch with us via our support form if you have an active Gravity Perks license so we can take a closer look at your setup.
Best,
I did not want the count to display until it had reached a certain threshold. I tweaked David’s fine script to provide for this. Two optional fields are used: display_min (a number) and display_min_alt_text (alternate text).
http://snippi.com/s/d32esuf
Dean
Hi Dean,
Thanks for sharing with the community. We already followed up on this via email, but I wanted to post this in the comment thread so other customers could see it.
Cheers,
Hi there
Nice bit of code. I am showing the number of entries of the form – all good. But I also want to add a number to this every so often that reflects offline forms that are physically collected. Is there a way to do this?
Hi Steven,
We don’t have a ready solution for this one. If you don’t collect many offline, you could enter the physical form data into the Gravity Form.
Is it possible to show only last 7 days entries?
Hi Mareks,
This isn’t currently supported. If you are a Gravity Perks customer with an Advanced or Pro license, drop us a line and we can look into adding support for this.
Hello,
When I try to run this shortcode via do_shortcode, I get an error.
Here’s the PHP I’m using:
echo do_shortcode(“[gravityforms action="entry_count" id="1" format="comma"]“) . ‘ people have taken the pledge to…’;
I’ve tried to escape the quotes inside the do_shortcode function, but when i do that the shortcode isn’t even recognized.
Here’s the error I’m getting:
Parse error: syntax error, unexpected ‘entry_count’ (T_STRING), expecting ‘,’ or ‘)’ in pledgetally.php on line 3
You’ll need to use single quotes to wrap the shortcode.
'[gravityforms action="entry_count" id="1" format="comma"]'
I actually tried that. When I did that the error said that do_shortcode was an unrecognized function.
I’m currently using this shortcode but I’m wondering how to tweak it so it can display the number of entries from multiple forms. How can I add multiple for ids?
I would also like to know if this is possible… I am having a case where I need to show the total number of entries from multiple forms that are related to each other.
Hi Joeri,
This isn’t currently supported. If you are a Gravity Perks customer with an Advanced or Pro license, drop us a line and we can look into adding support for this.
Best,
This looks great, Is there anyway to display entries sent to a certain author email ? I currently use the below code to email the author of a particular page when a form entry is made.
What id like to do is create a page where that author can then see the entries which has been submitted to him, your code seems to do that, but obviously it would display ALL entries for that form, could someone help with what code id need to use narrow it down only authors saw their own entries from the same form.
It looks like this might help: https://wordpress.org/plugins/gravitywp-count/
Hi David! How to display sum of entries from date range? How to set start and end date and get the amount on a specific field?
Hi Alex, we do not currently have a solution for this.
Today I modified this shortcode and it works as [donations form=9 start_date=”2017-02-01″ end_date=”2017-02-03″] But I don’t know how to make input on HTML page:
Hi again David. You were so helpful earlier I thought I’d pose another question! Is there a way to show a counter for form submissions to the same form ID, but where the form is used on different URLs (this is a job board, I’d like to display the total amount of submissions per job).
Hello,
I want to add 45(or 35,75,200) as a fixed value to add on number of the resulting. For example entries total = 20. I want to add 45. result=65. I want to show 65.
$x = [gravityforms action="entry_count" id="1"] ; $result= $x + 45; echo $result;
My Php knowledge is very poor. I wrote something like this but it does not work. $x hasn’t a value.how can I do it?
Hi Berke, we don’t currently have a solution for this.
Thanks for the code, it works great! I would like to know how I could set a base number for it to start counting submissions from?
Hm, not sure I follow. Could you clarify?
I have an old form that had 300 submissions, then I deleted the form and I just rebuilt it so the submissions is currently sitting at 5 instead of 305. What I would like to know is can I input a starting number in the code eg 300 submissions and then it adds to this so right now my code would output 305 submissions. Then if I get another submission it goes to 306, 307 etc. Hope that makes sense :)
Is there a know way to get the count of a form based on the page the form was submitted on. Racking my noodle on how to do this, I’m trying to echo how many people have submitted the form based on the page url as the same form is pulled through via the template for each page if that makes sense.
It is possible but not with this simplistic function. It would require a custom query to the DB. If you’d like to hire us to write such a query, we’d be happy to help. Get in touch.
Ahh no problem David, I thought there may of been a simple way of checking if an entry contained a value, never mind.
Great snippet! Using it for “total contributors” count. I’d also like to use it for “Total $ paid”. Each entry is a payment, so I’d like to display how much money we have raised so far. Let me know if that is possible.
Hi Adriana,
I built a recent site that needed something very similar to what you are describing. The only difference is I was displaying total miles logged.
In order to display the total amount raised, you’d need to add the values from each form entry.
This snippet will allow you to retrieve the total value of a specific form field for all entries. I also added some additional instructions to help you use the value where needed.
https://gist.github.com/hirejordansmith/348e6d32d3a1ed75bcb4e27f2bc8acb3
Ok that pretty genius, no lie. hmm… What about if you have 2 fields?
customer gets asked “are you individual or company?”
Individual has to pick their contribution of $5, 10, 20 or 30 from field id 3.
Company has to pick their contribution of $20, 40, 80 or 100 from field id 4.
I still want to show total raised in one display [total sum]
Thoughts?
Hi Adriana,
You can collect as many field totals as you want and assign to a variable then just add the totals together in a “total_sum” variable.
I’ve updated the gist in my first link to show how this is done. Enjoy!
HI David, From now I can view the counter above or below the form Can I use this number within the module or store it in some way?
Thanks in advance
Hi Axel, what do you mean “within the module”?
Does not seem to work with newest WordPress version. All I did was paste to bottom of functions.php. Removed php tag and save. It saved ok, but when I checked to see if website was working it took too long and gave timed out error.
There is something else at play here. This is a pretty simple snippet that shouldn’t cause any issues as you’ve described. As a first step, make sure you’ve installed this correctly.
https://gravitywiz.com/documentation/snippet-troubleshooting/
Hi David Smith, thanks for your help,
please do you have a tip on the counter handle this? Paid?
Hi, how i do format number: 0001, 0002???
thanks for help
Hi Lukas, this snippet doesn’t support formatting the number with leading zeroes.
The counter isn’t working for me at all. I have a few classes on the above page that have one entry in them but I can’t get the counter to show up. (I did them myself.)
Thank you.
Hi Kathy, I tested this locally and it’s working as expected for me. I’d confirm that you’ve installed the snippet correctly: https://gravitywiz.com/documentation/snippet-troubleshooting/
Thanks for fixing the functions.php file. Who knew one curly brace could throw everything off? Thanks for the catch! All is working beautifully now. Thanks for the help!
Hi,
I am showing the total count of a specific field in all entries with the snippet below, but tried to modify it with some code from your snippet, in order to show only include starred entries; Can you possible shed some light, please:
`function gravitywp_count_func ( $atts, $content = null ) { extract( shortcode_atts( array( ‘formid’ => ‘formid’, ‘field’ => ‘field’ ), $atts ) );
} return $gwp_count; }
add_shortcode( ‘gravitywp_count’, ‘gravitywp_count_func’ );
?> `
Hi, Further to my earlier comment ( not yet approved ), I have managed!
I changed $search_criteria = null; to $search_criteria[‘field_filters’][] = array( ‘key’ => ‘is_starred’, value => true );
and then simple change the status to STARRED for entries to be included.
Thank you,
Awesome! Glad you were able to get this sorted. :)
Hi David,
Thanks for this very useful snippet.
Is it possible to display entries count by parameter value. I have one form that serves multiple purposes. Say booking an event, sending an invite, scheduling an event, requesting a quote.
Can I display no. of times an event has been booked by using your shortcode like, [gravityforms action="entry_count" id="my_form_id" field_values='event_action=book this event']
Or display number of event invites sent out by using [gravityforms action="entry_count" id="my_form_id" field_values='event_action=invite a friend']
Hope you will help me achieve this.
Many Thanks.
Hi Prati, this is possible with custom code but not out of the box with this snippet.
Hi David,
Do you think it might be possible to make each form act independently when counting the number of entries. For example if i have put the same form on multiple posts but want to count the number of entries independently.
I would hugely appreciate the help! Also if you think it is possible could you point me in the way of a developer who could help implement this.
Thanks,
Hugo
I’ve written some code that does something similar here. You could pull the “is_limit_reached()” function out of the class and strip it down so that it simply returns the entry count. I’ve highlighted the line where it fetches the entry count by embed URL here.
Hi there, I inserted the shortcode but it’s not working :-(
http://www.yellow-giants.com/test
How have you configured the shortcode?
Yes I have. My form ID is 1. So I put [gravityforms action="entry_count" id="1"]
See page I have on Website field. That’s the form, there are 3 entries in form but there’s a 0 showing there.
Regards,
Hi there.
How do I register on this site to get support? I need this snippet to work on my site.
Regards
Hi David,
great snippet! Can you give more information about hiring you to modify it to show only the number of entries of logged user?
Thank you in advance,
Sergio
Hi Sergio, just responded to your email.
Hi
How can i display only current user/logged in users their number entries
thank you
This is not readily possible with this snippet. Get in touch if you’re interested in hiring me to write this.
Wow! This is fantastic!!! Is there any way to use this but have it pull only the number of entries with the author_name of the particular post?
I have a single form that is pulling the reply email from the author_name and then sends the notification with that field dynamically populated. However, it’s still the same form id across all the posts. So, for instance, if I have 20 posts with 5 authors and each one gets a single form entry, the counter I have in place (that works terrifically already, BTW) would show 20 entries on every one of those posts.
If I need to communicate in a different way with you all, let me know. Thanks for your help!!!
Hi Robby, this shortcode is limited in that it uses a very simple Gravity Forms function that gets the total count for each form without the ability to filter by entry values. You could write something custom using the GFAPI::get_entries() method to fetch the desired entries and then use PHP’s count() function to get the number of entries retrieved.
I’m curious if it would be possible to add constraints to this snippet? Specifically, I am looking for a way to display the number of entries by the user that is signed in. I’d like to display this at the top of my form (log-in is required): “This is the Nth time you have signed in”.
would be cool if this could work with the limit submissions per ip, say if you allow 3 per 24 hours, it shows the amount left the user could submit
Great snippet…THANK YOU. FYI you need not add the call to PHP on the first line, that will give you the white screen of death.
thanks again