Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Custom_Events_Date_Range_Filter extends Date_Range_Filter
- {
- public static function setup()
- {
- parent::setup(); // optionnal
- }
- public static function filter_main_query($wp_query)
- {
- global $typenow, $pagenow;
- /**
- * Override queries for bookings
- */
- if ($typenow == 'event') {
- if (
- is_admin() && $wp_query->is_main_query() && in_array($pagenow,
- array('edit.php')) && !empty($_GET['date_from']) && !empty($_GET['date_to'])
- ) {
- $from = explode('/', sanitize_text_field($_GET['date_from']));
- $to = explode('/', sanitize_text_field($_GET['date_to']));
- $from = array_map('intval', $from);
- $to = array_map('intval', $to);
- if (
- 3 === count($to) && 3 === count($from)
- ) {
- list( $year_from, $month_from, $day_from ) = $from;
- list( $year_to, $month_to, $day_to ) = $to;
- } else {
- return $wp_query;
- }
- $from_dt = $year_from."-".sprintf('%02d', $month_from)."-".sprintf('%02d', $day_from)." 00:00:00";
- $to_dt = $year_to."-".sprintf('%02d', $month_to)."-".sprintf('%02d', $day_to)." 23:59:59";
- $wp_query->set(
- 'meta_query',
- array(
- array(
- 'key' => 'start_date',
- 'value' => array($from_dt, $to_dt),
- 'compare' => 'BETWEEN',
- 'type' => 'DATETIME'
- )
- )
- );
- }
- } else {
- $wp_query = parent::filter_main_query($wp_query);
- }
- return $wp_query;
- }
- }
- remove_action('plugins_loaded', array('Date_Range_Filter', 'setup'));
- add_action('plugins_loaded', array('Custom_Events_Date_Range_Filter', 'setup'), 20);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement