Problem: I would like to use Views to display current or future events created by The Events Calendar, but the custom code I have in place isn't working as expected.
Solution: Use the following custom filter manipulation to filter events:
toolset_snippet_security_check() or die( 'Direct access is not allowed' ); /** * Filter event query to show future events */ function tssupp_filter_event_query( $view_args, $view_settings, $view_id ){ if ( in_array( $view_id, array( 6090,3499,4451,42214 ) ) ) { // Edit view IDs if ( ! isset( $view_args['meta_query'] ) ) { $view_args['meta_query'] = array(); } $today = strtotime("0:00"); $meta_query = array( 'key' => '_EventStartDate', 'value' => date("Y-m-d H:i:s", $today), 'type' => 'DATETIME', 'compare' => '>=' ); $view_args['meta_query'][] = $meta_query; } return $view_args; } add_filter( 'wpv_filter_query', 'tssupp_filter_event_query', 101, 3 );
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 12 replies, has 2 voices.
Last updated by 5 years, 3 months ago.
Assisted by: Christian Cox.