Home › Forums › Calendar Products › Events Calendar PRO › Hiding past events causes event start date to equal event end date?
- This topic has 5 replies, 2 voices, and was last updated 10 years, 6 months ago by
Nico.
-
AuthorPosts
-
September 28, 2015 at 10:49 am #1009326
integrity
ParticipantHello 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; }September 28, 2015 at 2:05 pm #1009435Nico
MemberHi @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,
NicoSeptember 28, 2015 at 2:38 pm #1009457integrity
ParticipantHi Nico,
The start date displays correctly if I comment out the
add_filterline.
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.
September 29, 2015 at 1:31 pm #1009804Nico
MemberHi @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,
NicoSeptember 29, 2015 at 2:03 pm #1009823integrity
ParticipantThe 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.
September 29, 2015 at 3:12 pm #1009845Nico
MemberGood 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 -
This reply was modified 10 years, 6 months ago by
-
AuthorPosts
- The topic ‘Hiding past events causes event start date to equal event end date?’ is closed to new replies.
