PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

display entries left as a shortcode (solution here)

  1. Hey guys - I wrote a shortcode that allows you to display the amount of entries left as a shortcode.

    Its useful if you want to put a link to a page with a form on it, and display the amount of entries left. I've also made it so if there are 0 entries left, it says its sold out...you can customize that if you want.

    add this to your functions and [spotsleft id="x"] will be the shortcode on your site. x will be the id of the form.

    [php]
    function spotsleftShortcode($atts, $content=null) {
    
    	extract(shortcode_atts(array(
    	'id' => ''
    	), $atts));
    
    	$form_id = $id;
    	$form = RGFormsModel::get_form_meta($form_id);
    	$entry_count = RGFormsModel::get_lead_count($form['id'], '');
    	$entries_left = $form["limitEntriesCount"] - $entry_count;
    
    	if($entries_left > 1):
    		$entries_left_message = $form['title']. ' – Only ' . $entries_left . ' spots left!';
    	elseif($entries_left == 1):
    		$entries_left_message = $form['title']. ' – Only ' . $entries_left . ' spot left!';
    	else:
    		$entries_left_message = $form['title']. '  – Currently sold out.  Please fill out our waiting list if you wish to join';
    	endif;
    	return $entries_left_message;
    }
    
    add_shortcode('spotsleft', 'spotsleftShortcode');
    Posted 9 years ago on Friday June 8, 2012 | Permalink
  2. Thanks for posting your solution!

    Posted 9 years ago on Friday June 8, 2012 | Permalink
  3. No problem! I LOVE this plugin. I wasted $75 on an events plugin that did not do everything my client wanted...so now im using this along with all in one calendar plugin and everything is working perfectly. So worth the $200.

    Thanks!!!

    Posted 9 years ago on Friday June 8, 2012 | Permalink
  4. This is great! Is there a way to make it so it will work if you have several options/events to choose from in a single form?

    Posted 9 years ago on Thursday June 14, 2012 | Permalink
  5. This looks great! Where do I have to place the code? I tried my theme's functions.php but that didn't work...

    Thanks in advance!

    Posted 8 years ago on Sunday July 22, 2012 | Permalink
  6. It certainly does go in your theme's functions.php. Once you've done that, you need to use the shortcode in your post, page or template. What happened when you tried to use it?

    Posted 8 years ago on Monday July 23, 2012 | Permalink
  7. When I add the code to my theme's functions.php, after uploading my site doesn't load but gives an error: Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /public/sites/www.ipadacademy.nl/wp-content/themes/fusion/functions.php on line 25

    I pasted the code right above the ?> that is already there. I have no knowledge of php, but would love to get this to work :-)

    Posted 8 years ago on Monday July 23, 2012 | Permalink
  8. Please post your complete functions.php at pastebin.com or pastie.org and we'll help you find the syntax error. That should be all there is to it.

    Posted 8 years ago on Monday July 23, 2012 | Permalink
  9. My code: http://pastebin.com/wKmC4KBz

    This gives the following error: Parse error: syntax error, unexpected T_STRING in /public/sites/www.ipadacademy.nl/wp-content/themes/fusion/functions.php on line 35

    Thanks for your help!

    Posted 8 years ago on Monday July 23, 2012 | Permalink
  10. When I check the syntax of that file, there is no error on line 35. What version of PHP are you using? (Looks like 5.3.3, which should be OK)

    Can you email me ( chris@rocketgenius.com ) a copy of your theme's functions.php instead of pasting it online? Maybe the online service corrected the syntax or something?

    Are we certain this is the correct functions.php you posted at pastebin.com - the one in use for your theme?

    Posted 8 years ago on Monday July 23, 2012 | Permalink
  11. Problem solved! Thanks to David Smith at Gravitywiz, who discovered that the minus sign on this line is actually an mash: $form["limitEntriesCount"] - $entry_count

    Changing that to a normal minus sign made it work. Thanks for all the efforts!!

    Posted 8 years ago on Monday July 23, 2012 | Permalink
  12. David Peralty

    Thanks for posting an update.

    Posted 8 years ago on Monday July 23, 2012 | Permalink
  13. I edited the code in this post to prevent future problems.

    Posted 8 years ago on Tuesday July 24, 2012 | Permalink

This topic has been resolved and has been closed to new replies.