eventsmanager

Custom Scope Today Only

Jun 12th, 2020
66
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Usage: [events_list scope="today-only"]
  3. */
  4.  
  5. add_filter( 'em_get_scopes','my_em_today_scopes',1,1);
  6. function my_em_today_scopes($scopes){
  7. $my_scopes = array(
  8. 'today-only' => 'Today Only'
  9. );
  10. return $scopes + $my_scopes;
  11. }
  12.  
  13. add_filter( 'em_events_build_sql_conditions', 'my_em_today_scope_conditions',100,2);
  14. function my_em_today_scope_conditions($conditions, $args){
  15. if( !empty($args['scope']) && $args['scope']=='today-only' ){
  16. $date_today = date('Y-m-d',current_time('timestamp'));
  17. $conditions['scope'] = " (event_start_date = CAST('".$date_today."' AS DATE) AND event_end_date <= CAST('".$date_today."' AS DATE))";
  18. }
  19. return $conditions;
  20. }
RAW Paste Data