Home › Forums › Calendar Products › Events Calendar PRO › Removing upcoming events if they have started
- This topic has 5 replies, 2 voices, and was last updated 6 years, 8 months ago by PHILLIPA.
-
AuthorPosts
-
August 10, 2017 at 2:56 am #1333325PHILLIPAParticipant
We have reused the bottom code block – which works fine. If an event over days has started it removes it from the listings. The thread suggested that a test for $query->is_main_query() should be included:
have tried this but it stops working
if ($post_type == 'tribe_events' && $query->is_main_query() )
function start_date_strict($query) { $post_type = $query->query_vars['post_type']; if ($post_type == 'tribe_events') { $filterDate = current_time('Y-m-d H:i:s'); if (!empty( $_REQUEST['tribe-bar-date'] ) ) { $filterDate = $_REQUEST['tribe-bar-date']; } $query->query_vars['meta_query'][] = array( // restrict posts based on meta values 'key' => '_EventStartDate', // which meta to query 'value' => $filterDate, // value for comparison 'compare' => '>=', // method of comparison 'type' => 'DATETIME'); } } add_filter( 'tribe_events_pre_get_posts', 'start_date_strict', 100, 1 );
August 10, 2017 at 12:43 pm #1333664ShelbyParticipantHey Phillipa,
Thanks for reaching out, I’m happy to help. 🙂
Based on the code you pasted, it should work as described without the modification I think. Could you double check your timezone settings (both WP and for our plugin) and let me know if they’re aligned with one another?
Let me know, and we’ll work on this from there!
Best,
Shelby 🙂
August 11, 2017 at 12:11 am #1333930PHILLIPAParticipantHi Shelby
We found the code here:
https://theeventscalendar.com/support/forums/topic/filter-events-with-start-date-after-now/On the tail end of this Brian suggests that $query->is_main_query() should be included to avoid problems with other views.
The code block is working fine – I’m just a bit unsure how to incorporate $query->is_main_query()
Thank you
August 14, 2017 at 5:04 pm #1335222ShelbyParticipantHi there,
I’ve added it into the code below so that you can copy and paste. 🙂
//All the events must start after the date we filter by function start_date_strict($query) { $query->is_main_query(); $post_type = $query->query_vars['post_type']; if ($post_type == 'tribe_events') { $filterDate = current_time('Y-m-d H:i:s'); if (!empty( $_REQUEST['tribe-bar-date'] ) ) { $filterDate = $_REQUEST['tribe-bar-date']; } $query->query_vars['meta_query'][] = array( // restrict posts based on meta values 'key' => '_EventStartDate', // which meta to query 'value' => $filterDate, // value for comparison 'compare' => '>=', // method of comparison 'type' => 'DATETIME'); } } add_filter( 'tribe_events_pre_get_posts', 'start_date_strict', 100, 1 );
Please let me know if you need anything further on this!
Best,
Shelby 🙂
September 5, 2017 at 9:35 am #1344940Support DroidKeymasterHey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.
Thanks so much!
The Events Calendar Support Team -
AuthorPosts
- The topic ‘Removing upcoming events if they have started’ is closed to new replies.