Created
February 5, 2020 18:20
-
-
Save MikeiLL/81fe88857be98879aa7c5892c4b4243e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'em_events_build_sql_conditions', 'my_em_scope_conditions',1,2); | |
function my_em_scope_conditions($conditions, $args){ | |
if( !empty($args['scope']) && $args['scope']=='today-upcoming' ){ | |
$start_date = date('Y-m-d',current_time('timestamp')); | |
$end_date = date('Y-m-d',current_time('timestamp')); | |
$start_time = date('H:i',current_time('timestamp')); | |
$end_time = '23:59'; | |
$conditions['scope'] = "((event_start_date BETWEEN CAST('$start_date' AS DATE) AND CAST('$end_date' AS DATE)) OR (event_end_date BETWEEN CAST('$end_date' AS DATE) AND CAST('$start_date' AS DATE))) AND ((event_start_time BETWEEN CAST('$start_time' AS TIME) AND CAST('$end_time' AS TIME)) OR (event_end_time BETWEEN CAST('$start_time' AS TIME) AND CAST('$end_time' AS TIME)))"; | |
} | |
if( !empty($args['scope']) && $args['scope']=='month-upcoming' ){ | |
$start_date = date('Y-m-d',current_time('timestamp')); | |
$next_day = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') + 1, date('Y'))); | |
$end_date = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d') + 30, date('Y'))); | |
$start_time = date('H:i',current_time('timestamp')); | |
$end_time = '23:59'; | |
$conditions['scope'] = "((event_start_date = CAST('$start_date' AS DATE) AND event_start_time BETWEEN CAST('$start_time' AS TIME) AND CAST('$end_time' AS TIME)) OR (event_start_date BETWEEN CAST('$next_day' AS DATE) AND CAST('$end_date' AS DATE)))"; | |
} | |
return $conditions; | |
} | |
add_filter( 'em_get_scopes','my_em_scopes',1,1); | |
function my_em_scopes($scopes){ | |
$my_scopes = array( | |
'today-upcoming' => 'Upcoming Today', | |
'month-upcoming' => 'Upcoming Month' | |
); | |
return $scopes + $my_scopes; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment