Skip Navigation

[Resolved] Views and Event Calendar Pro – date offset – how show events from today

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

Problem: I am using Event Calendar Pro to create and manage events. I would like to create a View of all current and upcoming events, but the Query Filter doesn't seem to be working as expected.

Solution: Use custom code to adjust the Query Filter to respond to the date format used by Event Calendar Pro.

function tssupp_filter_event_query( $view_args, $view_settings, $view_id ){
  
  if ( in_array( $view_id, array( 12345 ) ) ) { // Edit view IDs
  
    if ( ! isset( $view_args['meta_query'] ) ) {
     
      $view_args['meta_query'] = array();
    }
     
    $meta_query = array(
     
      'key'     =>  '_EventEndDate',
      'value'   =>  date("Y-m-d H:i:s"),
      'type'    =>  'NUMBER',
      '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 support ticket is created 6 years 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)

This topic contains 3 replies, has 2 voices.

Last updated by tomaszW-2 6 years ago.

Assisted by: Christian Cox.

Author
Posts
#1144224

Tell us what you are trying to do?
I try to make View list with upcoming events from Events Calendar Pro.

I did it but list contain also old events (like from yesterday ect). I want to figure out a way to offset View output. Event date field is stored in '_EventStartDate' in format like: 2018-11-16 08:00:00
Tried to Filter Query with field '_EventStartDate' is 'DATE' (tried also DATETIME) bigger than 'NOW', 'TODAY' etc but this doesnt work.

Is there way to make it?

What is the link to your site?
hidden link ('NAJBLIŻSZE WYDARZENIA' box)

#1144498

Hi, Views date filters are designed to work with Types date fields. Types date fields store dates as Unix timestamps, but the _EventStartDate isn't a Unix timestamp. It's stored as a different data type in the database. So a bit of custom code is required to convert the date format for Views.

function tssupp_filter_event_query( $view_args, $view_settings, $view_id ){
 
  if ( in_array( $view_id, array( 12345 ) ) ) { // Edit view IDs
 
    if ( ! isset( $view_args['meta_query'] ) ) {
    
      $view_args['meta_query'] = array();
    }
    
    $meta_query = array(
    
      'key'     =>  '_EventStartDate',
      'value'   =>  date("Y-m-d H:i:s"),
      'type'    =>  'NUMBER',
      'compare' =>  '>'
    );
    
    $view_args['meta_query'][] = $meta_query;
 
  }
  
  return $view_args;
}
add_filter( 'wpv_filter_query', 'tssupp_filter_event_query', 101, 3 );

Replace 12345 with the numeric ID of this View, or a comma-separated list of numeric IDs.
https://toolset.com/forums/topic/date-comparison-error-with-tribe-events-calendar-after-update/#post-1117132

#1144500

Awesome! Thank you.

I had to make little change, because your solution hide events which are currently happening, so I just changed field to 'key' => '_EventEndDate',

Best regards

#1144501

My issue is resolved now. Thank you!