Custom Scope Filter not works
-
Hi guys,
I need to create a custom scope filter:I would like to have all events from 6am of today to 6am of tomorrow.
So if today is 2016-04-26, I’d like to have all events from the 6am of 2016-04-26 to midnight of 2016-04-26 plus event from midnight of 2016-04-27 to 6am of 2016-04-27.
Here my code:
add_filter( 'em_events_build_sql_conditions', 'custom_today_scope_conditions',1,2); function custom_today_scope_conditions($conditions, $args){ if( !empty($args['scope']) && $args['scope']=='today-custom' ){ $today_date = date('Y-m-d',current_time('timestamp')); $tomorrow_date = date('Y-m-d',strtotime("+1 day", current_time('timestamp'))); $conditions['scope'] = " (event_start_date = CAST('$today_date' AS DATE) and EXTRACT(HOUR FROM event_start_time) > 6 ) OR (event_start_date = CAST('$tomorrow_date' AS DATE) and EXTRACT(HOUR FROM event_start_time) < 6 )"; } return $conditions; } add_filter( 'em_get_scopes','my_em_scopes',1,1); function my_em_scopes($scopes){ $my_scopes = array( 'today-custom' => 'Today Custom' ); return $scopes + $my_scopes; }and my working query (tested on phpMyAdmin):
SELECT * FROM "SqE_em_events" WHERE ("event_start_date"= '2016-04-26' and EXTRACT(hour FROM "event_start_time") > 6 ) or ("event_start_date" = '2016-04-27' and EXTRACT(hour FROM "event_start_time") < 6 )
( you have to substituite ” with ` )Thank you very much for any help
The topic ‘Custom Scope Filter not works’ is closed to new replies.