How to distinguish past events from current events in the loop?

WordPress Event Management, Calendars & Registration Forums General Question How to distinguish past events from current events in the loop?

This topic contains 1 reply, has 2 voices, and was last updated by  Stephen Harris 5 years, 9 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #30895

    Hi,

    we’ve made our own “event archive”. We basically pull all events like in a standard WordPress loop

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    

    How can we check, if events are past events? I imagine something like this

    if eo_is_past_even($postID) echo '<h2>Event has expired!</h2>';
    

    Is that possible somehow?

    Thanks.

    Manuel Geissinger
    #30905

    Hi Manuel,

    It depends what you mean by past event? If this is a recurring event, do you want to check if all occurrences are past? Or just that there are no occurrences currently running?

    If the former, what does it mean for an occurrence to be ‘past’? Do you mean: the occurrence has already started, or the occurrence has finisihed.

    To check the current occurrence:

     $now = new \DateTime();
     if(eo_get_the_end(DATETIMEOBJ) < $now){
         //Occurrence has finished
     } else if(eo_get_the_start(DATETIMEOBJ) < $now){
         //Occurrence has started, but not finished
     } else {
         //Occurrence has not started
     }
    
    Stephen Harris
Viewing 2 posts - 1 through 2 (of 2 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.