<?php

class ds1_DateRange{
 
	function __construct(){
		add_filter( 'months_dropdown_results', '__return_empty_array' );
 		add_action( 'restrict_manage_posts', array( $this, 'form' ) );
 		add_action( 'parse_query', array( $this, 'filterquery' ) );
 
	}
	function form(){
 
		$from = ( isset( $_GET['ds1_DateFrom'] ) && $_GET['ds1_DateFrom'] ) ? $_GET['ds1_DateFrom'] : '';
		$to = ( isset( $_GET['ds1_DateTo'] ) && $_GET['ds1_DateTo'] ) ? $_GET['ds1_DateTo'] : '';
 
		echo '<style>
		input[name="ds1_DateFrom"], input[name="ds1_DateTo"]{
			line-height: 28px;
			height: 28px;
			margin: 0;
			width:125px;
		    border-radius: 20px;
		}
		</style>
 
		<input type="date" name="ds1_DateFrom" placeholder="Date From" value="' . esc_attr( $from ) . '" />
		<input type="date" name="ds1_DateTo" placeholder="Date To" value="' . esc_attr( $to ) . '" />';
 
	}
 
	/*
	 * The main function that actually filters the posts
	 */
	function filterquery( $admin_query ){
		global $pagenow;
 
		if (
			is_admin()
			&& $admin_query->is_main_query()
			// by default filter will be added to all post types, you can operate with $_GET['post_type'] to restrict it for some types
			&& in_array( $pagenow, array( 'edit.php', 'upload.php' ) )
			&& ( ! empty( $_GET['ds1_DateFrom'] ) || ! empty( $_GET['ds1_DateTo'] ) )
		) {
 
			$admin_query->set(
				'date_query', // I love date_query appeared in WordPress 3.7!
				array(
					'after' 	=> sanitize_text_field( $_GET['ds1_DateFrom'] ), // any strtotime()-acceptable format!
					'before' 	=> sanitize_text_field( $_GET['ds1_DateTo'] ),
					'inclusive' => true, // include the selected days as well
					'column'    => 'post_date' // 'post_modified', 'post_date_gmt', 'post_modified_gmt'
				)
			);
 
		}
		return $admin_query;
    }
    
 
}
new ds1_DateRange();
