Skip Navigation

[Resolved] view to show current or future events from The Events Calendar

This thread is resolved. Here is a description of the problem and solution.

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

100% of people find this useful.

This support ticket is created 5 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

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)

Tagged: 

This topic contains 12 replies, has 2 voices.

Last updated by Steve 5 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1365581
griffin-view-screen-capture.jpg

I have a view that should show events (the events calendar) that are either happening on the the current date or in the future- but for some reason they drop off several hours before the event takes place so last minute people are unable to see it.

Ive checked our utc time zone which is correct- Also i have a piece of custom code you had previously supplied tssupp_filter_event_query that if i remeber converts the event calendar start dates to numbers and the form id is in the form array correctly - My query is attached.

Im hoping you can help me here- wed even be happy if the event stay available till the the day after its start date

Thanks

#1365833

Hi, what if you try setting the filter to be lower than FUTURE_DAY(1)? That should show anything up until midnight tonight/early tomorrow.

#1365849

Thanks Christian - that's better - but the calculation now is exactly 4 hours off. Its 5.34Pm in my time zone. My test event for today's day will display if i make its time 9:35Pm or greater

If i change the event date to 9.33 it vanishes

#1366351

Okay I would need to take a look at your database to see how these events are scheduled, and compare that with local timezone settings. May I log into your admin area to create a site clone with the Duplicator plugin?

#1366605

Sorry I'm getting an login error. Is there an IP restriction? If not, can you check those credentials and provide an update if necessary?

#1366683

Unfortunately I can't even clone the database alone with Duplicator Pro, it's hanging up every time and I'm not having any luck. Can you create a SQL dump file from your host panel? I might be able to work with that.

#1366779

I can sure- how best to get it to you

#1366823

You can post it to a Dropbox or Drive account and provide a download link here in the forum. Those links are obscured from public view automatically, for your security.

#1366831

Here you go Christian thanks

hidden link

#1366861

Just to be clear, should this View show events that started "yesterday" and continue through "tomorrow" for example, or only events starting on or after "today"?

#1366871

So its events that haven't happened yet. So who's start date is today or in the future

Thanks

#1366877

Here is an update to the custom code snippet:

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 );

In this snippet I've added some code that sets the comparison to begin at 0:00 today, in the server's NYC timezone. Then in the View editor, you should remove the Query Filter for _EventStartDate and allow this code to handle the date filtering.

#1367569

My issue is resolved now. Thank you!