Shortcode: Display Number of Entries Left
This shortcode extends the [gravityforms] shortcode, providing a custom action to retrieve the number of entries left based on the form’s entry limit.
October 21, 2013: Added "format" parameter which supports either a "comma" or "decimal" value for formatting the number of entries left.
Looking for a way to display the number of entries submitted? We’ve got a shortcode for that too!
I’ve had many users ask me about this since I published the Display Number of Entries Left… snippet back in April. I wrote a follow up article which demonstrated how to display this entry limit in the sidebar. Special thanks to Ty who pointed out this would be much better served as a shortcode.
After installing this snippet, you will be able to retrieve your form’s entries left with the following shortcode:
[gravityforms action="entries_left" id="your_form_id"]
How do I install this snippet?
Easy peasy. Just copy and paste the code above into your theme’s functions.php file.
How do I use this shortcode?
Very carefully. I’m kidding. Fire at will. Just enter your form ID and the shortcode will return the number of entries left.
Would you like to use this shortcode in the sidebar of your website? Check out the Shortcode Widget plugin!
The Shortcode
[gravityforms action="entries_left" id="your_form_id"]
Example
[gravityforms action="entries_left" id="2"]
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!
Continue Reading about Shortcodes
If you’re looking for more information about Gravity Forms shortcodes — including all the different types, shortcode parameters, and how to get started using each, check out our comprehensive guide on Gravity Forms Shortcodes.
Hello,
nice feature to show the remaining amount of form submissions left. It works perfectly. However, is there a way to add some custom text before and/or after the counter?
So that for example, it will say: XXX submissions remaining.
Cheers in advance.
Andre
Hi Andre,
You can add your custom text before or after the shortcode wherever you decide to place it. Rough example:
Helloooo :-)
I have installed the snippet and it works ! However, I have several reccurring events, created seperately and the snippet indicates the total of registries. Let me explain further :
1/ I have 4 events , Monday, Tuesday, Wednesday and Thursday. 2/ Each of them have a max entries of 48. 3/ John booked Monday, and Mary booked Thursday (= minus 2 entries) 4/ ALL my 4 entries show 46 (which is 48-2).
Why de deduction is not made on the day registered only ? Which should be MON 47, TUE 48, WED 48 and THU 47 ?
Thank you for your Help in this :-)
Tania
Hi Tania,
I think that is a better fit for GP Inventory. It lets you set limits on the individual items and/or dates on your form. You can then display the number remaining, and with scoped inventory that number is context aware of the current selections in the form.
Greetings great! the question is can filter the count according to members or users, ie showing the count for each user seperatedly. Regards
Hi,
From what I understand this is not supported, but this tutorial could work for you Gravity Forms Progress Meter. If you have an active Gravity Perks License, you can get in touch with us via our support form so can dig into this.
Best,
How do I style only the “entries left” line since it’s added in the lable tag? Thanks :)
Hi Tim,
Depending on how you’re using the shortcode, you can wrap a span tag around it and use inline CSS to style it
Best,
Thanks so much for this snippet! Has been a huge help for setting up a volunteer registration system. Is there an easy way to also display the total number of available entries? For example: “5 out of 20 spots available”
Hi Mark,
Show the spots left would require a bit of customization. You could probably try using Gravity Forms Limit Submissions or GP Inventory which don’t require any custom code!
Best,
nice code, but when i use this shortcode what get php error. ‘Notice compact(): Undefined variable: is_default’
how can i fix it?
Hi,
I was able to reproduce a similar issue locally. I’ll ping our dev team about this issue.
Cheers,
Hi, it’s possible to to link the number to purchases actually made? thiis parameter “approved_payments_only”
Hi Mauro,
Currently, this is not supported from what I understand but this snippet could work for you Gravity Forms Progress Meter
If you have an active Gravity Perks License, you can get in touch with us via our support form so can dig into this.
Cheers,
Great snippit and very helpfull to use!! Although I do have a bit of a problem.
The snippit works great while visiting the site with chrome, but doesn’t work while visiting the site with firefox or edge.
Any clue where to solve this?
Hello Barry, This is a bit of a strange one. When attempting to recreate this issue, I was unable to. Could you send us a link to the form in question so we can see what you see. Thanks! 😀
Solved, It seems that it was somehow related to some cache settings on the site.
Hi David, How are you? Is there a way to show only a single entry? In other words I want to show the total count but I also want to show how many clicks was made on a single poll.
Hi Michelle, we don’t have a solution for this one.
Love this code!
Have a question. I want to use this for workshops with limited places (12). But 1 entry can contains 1 or more participants. So for example: 3 entries with 4 participants each can fill the workshop and I need this in the code. Any suggestions?
And if this is possible an additional question. Can the count entries left also be shown in the form where the person who’s entering the entry can choice how many people he/she wants to subscribe? So, when there are for example 3 places left in a workshop and someone want to subscribes a few persons he/she sees that 3 is the maximum.
I would very much appreciate your answer.
Thanks in advance.
Regards,
Jorrit
Hi Jorrit, this sounds like a better fit for our Better Inventory snippet (which also supports it’s own shortcodes for showing remaining counts).
https://gravitywiz.com/better-inventory-with-gravity-forms/
Thanks! That looks promising, particularly in a situation in which the same registration form handles multiple events. Although I’m guessing it may not disallow registration of an event that’s full?
If you want to get into limiting the form based on “inventory”, this is probably the preferable solution.
https://gravitywiz.com/better-inventory-with-gravity-forms/
It also has several shortcodes for displaying the inventory left. The documentation for these blows but you can find the important details in my response to another user here:
https://gravitywiz.com/better-inventory-with-gravity-forms/comment-page-6/#comment-291178
A few more details on how you’d make this work for multiple events…
BTW, I reviewed Perks, and didn’t find an indication this functionality is included.
This is a great idea and easy implementation, but useless with say, a registration form if it handles a series of events. Unless(!) there is a way to reset the count; then it’s truly great.
I notice the author indicates in December 2015 that he could provide this solution to a commentor for payment. Any chance a simple solution for resetting could be published here to make this a more complete solution? Or perhaps there is a plugin now that includes that capability? I’d buy the plugin.
HI Ray, you might consider GF Chart for displaying a filtered count.
Thanks! I’m using Twig/Timber. The shortcode function only works when I put it inside TimberSite construct function where I have all the “add_filter” lines. Not sure why but it just works.
Interesting solution. Glad you got it working. :)
Hi, urgent help needed. Is there a way to set the limited selection counter to a radio button field. Details below: Is there a way to restrict specific radio button field(s) within the form to a limited number of selections like a countdown from X to zero. After the counter (number of predefined selections) reaches zero the field should be disabled (unavailable) for all other visitors that come later to make a selection.
Example: Select your teacher: _ Roy (10 classes left) _ Mark (3 classes left) _ Damon (0 classes left) (unavailable, not visible to the visitors anymore)
URGENT solution needed, thank you.
This plugin is what you need: https://gravitywiz.com/documentation/gravity-forms-limit-choices/
I want to show checkbox (checked) count after submission.. I want a shortcode for this to generate checkbox number.
Hi Shemul, you could use this snippet to store the selected count in a field and then use the merge tag for that field to display the count wherever: https://gist.github.com/spivurno/077fd21a993e9b573d46
Hi GravityWiz. This works well…to an extent. It doesn’t reset. I have my forms limited to 25 entries a day, I’ve submitted on the form once and every day since the count stays at “24 entries left”. Any ideas? Thank you.
Hi Joy, you are correct. Would you like to commission this enhancement? If so, get in touch.
When I paste this code into my functions.php file I get the white screen of death and an error “[02-Oct-2015 17:54:49 UTC] PHP Parse error: syntax error, unexpected ‘<‘ in /home2/journfz6/public_html/wp-content/themes/journey/functions.php on line 931”
Can you help?
Running PHP 5.4
Hi Josh, take a look at this help doc and let me know if your issue persists: https://gravitywiz.com/documentation/snippet-troubleshooting/
Hi, I have a dropdown with 3 LIMITED choice (5 times limit for each choice) and I would like to SHOW the number of times remaining next to each choice of the dropdown… can you help?
Hi Derek, are you using GP Limit Choices? If so, you can display a message next to each choice with the following snippet: https://gist.github.com/spivurno/7858140
Hi I wanted to know is there a way to have a countdown link to an entry in a gravity form?
Hey Jeremy, not sure I understand your question. Could you elaborate?
Hi
What I mean is there are countdown plugins – etc birthday and I wanted to know how i could have that take the date of someone’s profile automatically from a gravity form?
Would it be down to the countdown plugin?
Sorry, Jeremy. Still not following. Are you asking if it’s possible to use Gravity Forms as a countdown plugin or do you want to use data submitted via a Gravity Forms in a 3rd party countdown plugin?
Hello,
I need to subtract 2 instead of 1 if the user role is one specific. I think I can get into this in 2 ways:
Adding a conditional of that role in functions so I can just subtract 2 instead of 1 but I didn’t find the way to do this.
Adding a conditional so when a user with that role send the form the entry is added 2 times to the DB directly.
I have tried to add conditional statements to the form using “quantity” but this is not related with the number of entries so is not working.
I saw in the forms_model where is taking the number but I don’t really know how to apply this conditional correctly.
Any idea or tip of how can I get into this?
Thank you!
Hi Miguel,
I would recommend hiring a developer to assist with this customization. Codeable.io or WP Curve are two great options.
Bro how can i add php or tweak i would like to display counts only for the current user example when they are logged in i just added your code on my function.php can you help me
thank you
Hey Jasper, this is not readily possible with this snippet. Get in touch if you’re interested in hiring me to write this.
Hi there,
Great work and many thanks for all the PERK’S , will be purchasing within the next week.
I have a question in regard to the using the Display entries left snippets.
Wondered how they can be coded to display the amount of entries left specified using your other snippet –
” Better Limit Submission Per Time Period by User or IP” https://gravitywiz.com/better-limit-submission-per-time-period-by-user-or-ip/comment-page-2/#comment-155605
IE. that way if limited by IP or User ID will display different amounts of entries left.
I have only been able to get it to show the limits set in the gravity forms settings so far.
Cheers and thanks again, awesome work.
Hi Marcus, this would require some custom code. Get in touch if you’re interested in commissioning it.
Hey, Thanks for the reply,
Will contact you you via the link.
Cheers.
Many thanks for this snippet code. I am using it on a client site (link supplied), and am using the code to let people know how many spaces are left for a workshop. It is working great on all but one of the forms, and as far as I can see, there is no difference in the set up of this particular form.
The issue is that on this one form, even though there are only 6 out of the maximum 8 entries used, the “Entry Limit Reached Message” is showing.
My Shortcode are set up as follows:-
There are currently [gravityforms action="entries_left" id="13"] spaces left on this workshop. [gravityform id="13" name="Workshop - Sunday 8th March 2015" title="false" description="false" ajax="true"]
I also added the “Display Number of Entries Submitted” shortcode and it shows the fact that there are 6 entries and not 8.
[gravityforms action="entry_count" id="13"]
I’m confused as to why that might be. Do you have any ideas?
Thank you.
Hi David,
First off, thank you for this. Second, Iv’e seen that you’ve done much with displaying the amount of entries left, the entry count, etc….My question is, do you happen to know how I would go about getting a rounded up percentage of entries available based on the entry limit compared to the entry count? I.e The Count divided by the total and displayed as a full percentage? I know that this question isn’t specifically related to your post, but thought I’d try. Thank you in advance!
Here’s a quick function you can use: https://gist.github.com/spivurno/bab7f701e5a3eead6fa3
Hello David,
Do you think it is possible to do the following :
If number of remaining entries equals zero, then make the posts in which the form is embedded private?
Right now, I would just like to know if possible – later I will ask you for a quote for this snippet.
Kind regards,
Yves
Yes, this is possible. Is there a specific reason you would need to hide the page itself rather than just the form via GF’s default limit entries functionality?
Hello Yves,
I love such concepts, and i will prefer the post hidden rather than the form itself, reasons are posts have categories and navigation but forms do not have. I will like to know how to archive this function.
Thanks David,
I am using a number of forms on the same site, each with a limit of entries. How do I get the shortcode snippet to return the correct entry for the particular form
Thanks in advance Marc
Hi Marc, not sure I understand. Pass the form ID to get the entries left for that form. You can use the shortcode multiple times, each with a different form. Does that answer your question?
Thanks so much for getting back to me. I am a total hack when it comes to php. I am sure what I am asking should be known by anyone with basic skills, so pls forgive the question. I wouldn’t be offended if you told me to go back to school:)
I have multiple forms each with a limited number of entries set. I would like to display the Entries left for each form. By adding the form ID ( in this case 5) to the code line number 17. So $form = RGFormsModel::get_form_meta( $id ); becomes $form = RGFormsModel::get_form_meta( $id =5); it returns the Entries left correctly for form 5.
What do I need to change to get forms ID 7, 8 & 9 to display correctly
Thanks again in advance
You would use:
[gravityforms action="entries_left" id="7"]
[gravityforms action="entries_left" id="8"]
[gravityforms action="entries_left" id="9"]
Thanks very much David. I was being so stupid. Have a great day. Marc
Happy to help, Marc. :)
hi
this is a great little snippet as are some of the perks which we recently purchased
i have a question about the count itself. we have an event that can hold 400 people and we need to be able to count to that figure.
we have set up the form to have a simple are you taking a guest YES/NO radio button followed by further questions based on the initial option
the issue i have is if for example 200 people are invited and each takes a guest then that is fine and the number of entries left is displayed properly and we can limit the form at that – 200 entries and know that possibly that will be 200*2 which will give us our total number
as it stands if some people are not taking a guest, how do we determine the actual amount of available ‘entries’ left?
say 150 people are taking a guest and 50 are not then technically speaking that is only 350 ‘guests’ with 50 more than can come. hopefully that makes sense… it confused me when i read it back the first time ;p
is there a way gravity forms can actually do this – sorry bit of a novice
any help appreciated
cheers
First, thanks for being a Gravity Perks customer! It really does help keep the lights on here. :)
There isn’t a super straight forward way to handle this. The basic premise is that the entry itself would count for one “spot” and the additional guest would count as another “spot”. This is possible but would require some custom code to achieve. If you’re interested in commissioning me to write this code for you, I’d be happy to offer you a discount since you’re a Gravity Perks customer.;)
Get in touch if you’re interested.
Hello David,
Is there a way to show the number of Entries Left in the notification mail?
Hey Yves, GF notifications support shortcodes. You can add this shortcode right into the notification message.
Hi David, Is there anyway to display the number of total entries? something like: “XXX people submitted this form”
[gravityforms action="entries_count" id="your_form_id"]
Hi Mili, here is a snippet that adds support for an “entry_count” action on the [gravityforms] shortcode.
https://gist.github.com/spivurno/afac61057595ea9c625a
Usage would look like this:
[gravityforms action="entry_count" id="12" /]
It also supports retrieving the count by status (i.e. “trash”, “starred”, “unread”, “spam”).
[gravityforms action="entry_count" id="12" status="unread" /]
thanks! :)
David, Thank you. It’s working.
Glad to hear it!
This is a great snippet. Really helped me out with a project I’m working on. Works beautifully.
Question though…we want to create a form with a countdown to a certain number of signups (just like this shortcode would allow), but we want the count to reset after the number of entries is complete and continue to allow entries.
Do you have any suggestions on how we might accomplish this? I’m not sure if it’d be best to ditch the entry limit entirely and try to create some other kind of counting function and modify your shortcode to track it…or if there’s someway to swap the form for another once the maximum entries have been reached.
I’d really appreciate your expert advice. But in anycase, thanks again for a great snippet.
Hi Jesse, here is some basic code to get you started. The concept is that there is no configured entry limit. You specify the “cap” in the code and then it will “reset” the counter every time the cap is reached. For example, if there are 2 entries and the cap is 60, there are 58 submissions left. If there are 62 entries and the cap is 60, there are 58 submissions left. Make sense?
Nevermind, figured out a method to do this…just modified your shortcode to remove the checks for limitEntries, created a variable that holds the entry count rounded up to the nearest hundred and return this variable minus the entry count. So now it always counts down from 100 entries.
But now I have another question…can you think of any way you could conceivably display the count in real time? So if someone submits an entry while you’re viewing the page the number actually updates?
I’m guessing this is near impossible without modification, as I don’t know how the gravity forms PHP could pass this value in real time, but if you can think of a way I’d love to hear it and try it out. Thanks again.
Sorry, didn’t notice you’d replied to my first comment…would’ve thanked you instead of saying nevermind. I really appreciate the assistance.
No need to approve this comment, just didn’t know how else to reach you.
Think there’s any chance something like this could work in hand with Better Inventory to show how many products are left.
In my scenario products are tickets, and we have a limited number of tickets and would love to show the inventory instead of entries, as each entry can have several tickets purchased within it.
Great snippet though! Thanks again
Is there anyway to format the number to include commas?
Hi Samantha, I’ve updated the snippet above to support a “format” parameter on the shortcode. Example: [gravityforms action="entries_left" id="369" format="comma"]
THANK YOU!
Hi David
That is really a great code! Thanks a lot and we modified it also to a total entries / available entries and entries left.
Now we would like to have an overview for all of over events. How can we manage this code to show it in a listable view, without to add the code for each events? It should automatically search the forms based on a tag oder categorie. for Example: event 1 : 100 / 50 / 50 event 2 : 100 / 30 / 70
Thanks Don, Can you post your modified snippet? This is exactly what I need!
Hi David
Is there a way to enhance this great plugin for a list of forms. We have several forms, one per event. Now I would like to show all entries left in one list every event on a single line (with name, entries left).
Hey there! Great snippet. Is there a way to make it so I could have my 3 volunteer positions and the entries left beside them? As opposed to the entries left above the form itself.
Hi Amber, you can use this shortcode anywhere in your post content. Not sure how your content is setup but assuming you are outputting some content for each volunteer position, just add this shortcode after each position and style as needed. Let me know if I haven’t understood correctly.
I am excited to get this working. Looks like its just what I needed. I pasted the code into my functions.php file at the very end. When I use the short code I get the actual form itself and not the remaining entries. I have verified correct form ID, entries limited is set in the form settings. Did I possibly paste the code in the wrong place within the functions.php file? Thanks for any help you can offer.
I am looking for shordcodes which show the entry lists, not the form. originally,gravityform plugin shows the entries lists in Admin Panel, but I want to display the entries at the front page. if you could help thanks in advance
Hi Ronald, for now your best bet is using third-party Directory Add-on: http://wordpress.org/extend/plugins/gravity-forms-addons/
THANK YOU!!!! I have been looking for this all over and just stumbled upon this page. IT WORKS!! :) I can not believe a plugin this big(over 400k sold) would not have a option to retrieve data and use boolean strings…
So thank you very much for this. :)
Thank you very much, David! :)
Hm… it worked well but after I deleted some entries, the counter is fixed on the maximum number of entries defined within the Gravity forms…
Good catch, Kim. There was a small bug where it was also counting entries in your trash. I’ve updated the code to only count “active” entries towards the entry limit. :)
Thanks for the great snippet! I’ve added the code above but it looks like it’s still counting entries in the trash. When my form limit was meet it worked as it should but after deleting the entries the form would not return/display. I had to empty the trash before it started working again.
the php i’m using contains: $entry_count = RGFormsModel::get_lead_count($form[‘id’], ”, null, null, null, null, ‘active’);
Hi Gary,
I just tested this locally and entries in the trash were not counted towards the number of entries left. To be clear, are you saying the form itself wasn’t being limited or that the shortcode provided via this snippet was not working?
Sorry, my mistake. It is working. I entered the wrong form id…
Btw, how do I reset the counter?
The counter is based on the number of submitted entries. To reset the counter you would need to delete the current entries. You can do this quickly from the Forms page by checking the checkbox of the form for which you like to delete the entries and then select the “Delete Entries” bulk action: http://grab.by/hpYM
Not working. Same problem as Allan reported.
Copied the snipplet to the functions.php, used the shortcode. Result: Empty space.
Hi Kim, I just tested this again locally and am unable to recreate any issue. Here are some screengrabs of my setup:
For some reason, the shortcode doesn’t show any number, text or anything. Just empty space?
Should I change anything in the code I copy/paste into functions.php?
Hi Allan, it should be good to go. You’ll want to make sure you have an entry limit specified in your advanced form settings and that you’re referencing the correct form ID in the shortcode itself.