custom scope
-
I am making a mobile view for my calendar page. It will display an agenda.
I want to display the events using three scopes: today, tomorrow, day-after-tomorrow.
day-after-tomorrow needs to be a custom scope. I used the code below. Notice the way I structured the start and end dates:
$start_date = date(‘Y-m-d’,current_time(“+2 day”, current_time(‘timestamp’));
$end_date = date(‘Y-m-d’,strtotime(“+50 day”, current_time(‘timestamp’)));
The output showed results beginning Feb 6 (it is Jan 18) and then random events 6 months out. What do I need to do to fix this?
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']=='day-after-tomorrow' ){ $start_date = date('Y-m-d',current_time("+2 day", current_time('timestamp')); $end_date = date('Y-m-d',strtotime("+50 day", current_time('timestamp'))); $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))"; } return $conditions; } $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))"; add_filter( 'em_get_scopes','my_em_scopes',1,1); function my_em_scopes($scopes){ $my_scopes = array( 'day-after-tomorrow' => 'Day After Tomorrow' ); return $scopes + $my_scopes; }
The page I need help with: [log in to see the link]
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘custom scope’ is closed to new replies.