Your can use the “meta_query” argument of the query, I think is better than filter the post_where
:
add_action( 'pre_get_posts', 'bbwp_calendar_visible_events' );
function bbwp_calendar_visible_events( $query ) {
$postType="bbwp_calendar";
if ( !is_admin() && $query->is_main_query() ){
if ( is_post_type_archive( $postType ) ) {
$meta_query = array(
'relation' => 'OR',
//current time <= event_end_date
array(
'key' => 'event_end_date',
//Check https://codex.wordpress.org/Function_Reference/current_time
//to return the current time (today) in the same format
//you store the date in your custom field
'value' => current_time( 'timestamp' ),
'type' => 'DATETIME',
'compare' => '<=',
),
//event_end_date=""
array(
'key' => 'event_end_date',
//Check https://codex.wordpress.org/Function_Reference/current_time
//to return the current time (today) in the same format
//you store the date in your custom field
'value' => "",
'type' => 'DATETIME',
'compare' => '=',
),
);
$query->set( 'meta_query', $meta_query );
}
}
}
More info: