The Events Calendar
Getting "This event has passed." to show (3 posts)

  1. g4ry
    Posted 5 years ago #

    This is my first post on the entire WordPress forum, so I hope I'm submitting this info correctly.

    The "single.php" view template has a line of code that's supposed to indicate that the displayed event is in the past:
    <?php if (the_event_end_date() > time() ) { ?><small><?php _e('This event has passed.', $spEvents->pluginDomain) ?></small> <?php } ?>

    I've found a few apparent problems with this:

    • First, the data type for 'the_event_end_date()' and 'time()' seem to be different, so it's never compared correctly.
    • Second, even if they were the same data type, the direction of the ">" sign is wrong. It should be "<", indicating the current time must be later than the end date for the message to be displayed.
    • Finally, to get TEC to hide the event end time, I will give my event an end time that is before the event start time. Thus, it is possible with this code (if it was working correctly) that the event still hasn't started yet, but will say that it's over.

    To fix this, I made the following change:

    <?php if ( ( strtotime(the_event_start_date()) < time() ) && ( strtotime(the_event_end_date()) < time() ) ) { ?>
    <?php  _e( 'This event has passed.', $spEvents->pluginDomain) ?>
    <?php } ?>

    I used the strtotime() function to get the data into the correct datatype. Also, time() must now be after both the event start and end time before the message will be displayed.

    One lingering problem with this message is that it's displayed next to the iCal button, which doesn't really make sense. So one final change I did was to relocate the code to within the "Start:", "End:" and "Cost:" <dl> Definition List. This meant a few <dt> and <dd> tags needed to be added too. My new code for the section looks like this:

    <dl class="column">
    	<dt><?php _e('Start:', $spEvents->pluginDomain) ?></dt>
    		<dd><?php echo the_event_start_date(); ?></dd>
    	<?php if (the_event_start_date() !== the_event_end_date() ) { ?>
    		<dt><?php _e('End:', $spEvents->pluginDomain) ?></dt>
    		<dd><?php echo the_event_end_date();  ?></dd>
    	<?php } ?>
    	<strong><?php if ( ( strtotime(the_event_start_date()) < time() ) && ( strtotime(the_event_end_date()) < time() ) ) { ?>
    		<?php  _e( '<dt></dt><dd><em>(This event has passed.)</em></dd> <br />', $spEvents->pluginDomain) ?>
    	<?php } ?></strong>
    	<?php if ( the_event_cost() ) : ?>
    		<dt><?php _e('Cost:', $spEvents->pluginDomain) ?></dt>
    		<dd><?php echo the_event_cost(); ?></dd>
    	<?php endif; ?>
  2. thirstcard
    Posted 4 years ago #

    This is brilliant code although I would change the following




    I would also do the same for the end date.

    Then it works for me!

  3. Rob La Gatta
    Modern Tribe Support
    Plugin Author

    Posted 4 years ago #

    Hey dudes. Thanks for this! Interestingly enough we have an officially-supported "This Event Has Passed" feature coming in 2.0.5, which should be out over the next few days. So if you don't want to manually implement the suggestion above there will be an officially-supported feature that serves generally the same purpose.

    Hope that helps! Thanks again for sharing and if anybody has any other questions, just give me a shout.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • The Events Calendar
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic