Title: Custom Scope Filter not works
Last modified: August 31, 2016

---

# Custom Scope Filter not works

 *  Resolved [fersamp](https://wordpress.org/support/users/fersamp/)
 * (@fersamp)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/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
 * [https://wordpress.org/plugins/events-manager/](https://wordpress.org/plugins/events-manager/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [caimin_nwl](https://wordpress.org/support/users/caimin_nwl/)
 * (@caimin_nwl)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/custom-scope-filter-not-works/#post-7321334)
 * Hi,
 * What output are you getting with that code?
 * Which version of Events Manager are you using?
 *  Thread Starter [fersamp](https://wordpress.org/support/users/fersamp/)
 * (@fersamp)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/custom-scope-filter-not-works/#post-7321405)
 * Hi,
    I’m getting all future events, so I think that filter is not working. The
   EM version is 5.6.3.
 *  [caimin_nwl](https://wordpress.org/support/users/caimin_nwl/)
 * (@caimin_nwl)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/custom-scope-filter-not-works/#post-7321478)
 * Is the correct hour being extracted, either in your SQL query or within the filter?
 *  Thread Starter [fersamp](https://wordpress.org/support/users/fersamp/)
 * (@fersamp)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/custom-scope-filter-not-works/#post-7321486)
 * The query is correct because it works on phpMyAdmin.
    In the filter I don’t know,
   I’m asking that 🙂
 *  [caimin_nwl](https://wordpress.org/support/users/caimin_nwl/)
 * (@caimin_nwl)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/custom-scope-filter-not-works/#post-7321496)
 * I was suggesting that you add a check to your filter code to see what is being
   extracted, if any,

Viewing 5 replies - 1 through 5 (of 5 total)

 The topic ‘Custom Scope Filter not works’ is closed to new replies.

 * ![](https://ps.w.org/events-manager/assets/icon-256x256.gif?rev=3711454)
 * [Events Manager - Calendar, Bookings, Tickets, Appointments and more!](https://wordpress.org/plugins/events-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/events-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-manager/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [caimin_nwl](https://wordpress.org/support/users/caimin_nwl/)
 * Last activity: [10 years, 5 months ago](https://wordpress.org/support/topic/custom-scope-filter-not-works/#post-7321496)
 * Status: resolved