Hiding past events causes event start date to equal event end date?

Home Forums Calendar Products Events Calendar PRO Hiding past events causes event start date to equal event end date?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1009326
    integrity
    Participant

    Hello all,

    I’m trying to hide past event from the front-end on one of my websites. An older forum post had a solution (https://theeventscalendar.com/support/forums/topic/how-to-hide-past-events/) that works perfectly except for one thing: when I add the new meta_query, the event start dates are somehow altered.

    For example, an event with a start date of Sept 30th and an end date of October 3rd displays in the list and single-event views as having a start and end date of October 3rd.

    I can’t figure out why this is happening! Help?

    Code to filter old events from the frontend:

    add_filter('tribe_events_pre_get_posts', 'filter_tribe_all_occurences', 100);
    
    function filter_tribe_all_occurences ($wp_query) {
    	if ( !is_admin() )  {
    	  $new_meta = array();
    	  $today = new DateTime();
    
    	  // Join with existing meta_query
    	  if(is_array($wp_query->meta_query)) {
    	  	$new_meta = $wp_query->meta_query;
    		}
    
    	  // Add new meta_query, select events ending from now forward
    	  $new_meta[] = array(
    	          'key' => '_EventEndDate',
    	          'type' => 'DATETIME',
    	          'compare' => '>=',
    	          'value' => $today->format('Y-m-d H:i:s')
    	  );
    	  $wp_query->set( 'meta_query', $new_meta );
    	}
    	return $wp_query;
    }
    #1009435
    Nico
    Member

    Hi @integrity,

    Thanks for reaching out to us on this, I’ll try to help you out on this!

    Taking a look to the code, it seems to be fine! Also I don’t see how can it affect event start date on the front-end. Can you comment out the add_filter line and make sure this is the cause of the date change?

    Sorry if this is an obvious question but again, I don’t see how this snippet can affect the events display.

    Please let me know about it,
    Best,
    Nico

    #1009457
    integrity
    Participant

    Hi Nico,

    The start date displays correctly if I comment out the add_filter line.
    The start date also displays correctly if I comment out the $wp_query->set( 'meta_query', $new_meta ); line.

    The snippet of code that is displaying the start-end date is in my template’s tribe-events/list/single-event.php file:

    <!-- Schedule & Recurrence Details -->
    <div class="updated published time-details">
        <?php echo tribe_events_event_schedule_details() ?>
    </div>

    I dug into tribe_events_event_schedule_details() and found that it was using tribe_get_start_date(). I tried calling tribe_get_start_date() myself and it returned the incorrect date (the end date).’

    Bizarre.

    Thanks, let me know if I can provide any more info!

    • This reply was modified 10 years, 6 months ago by integrity.
    #1009804
    Nico
    Member

    Hi @integrity,

    Bizarre indeed! I’ve tried the code in my local install and it seems to work as expected, no changes in the dates. I’m seeing everything fine in the listings and in the single event view. So not sure what might be happening in your case. Are you checking this on list view? Widgets?

    Can you try to use this snippet with default TweentyFifteen theme and no other plugins but ours active? Also any special timezone settings or such?

    Sorry for the many follow-up questions but I’m a bit confused about what might be happening here!

    Please let me know if this tests shed some light over this,
    Best,
    Nico

    #1009823
    integrity
    Participant

    The problem was that I wasn’t running the latest version of the Event Calendar & Event Calendar PRO Plugins, apparently!

    The problem persisted on the TwentyFifteen theme with all other plugins deactivated. Then I updated the plugins and the problem was solved. I suppose some bug in the past version of the plugin was to blame.

    #1009845
    Nico
    Member

    Good catch @integrity!

    Probably it was some buggy behavior that got fixed in the latest release! Anyway glad to hear this is solved 🙂

    I’ll go ahead and close out this thread, but if you need help with anything else please don’t hesitate to create a new one and we will be happy to assist you.

    Best of luck with your project,
    Nico

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Hiding past events causes event start date to equal event end date?’ is closed to new replies.