Support

Account

Home Forums General Issues Query between dates using Date Picker fields Reply To: Query between dates using Date Picker fields

  • OMG what a pain. I got it!

    so use their tutorial on comparing dates but instead of date(‘Ymd’) use current_time

    $today = current_time('Ymd');
     
    $args = array (
        'post_type' => 'post',
        'meta_query' => array(
    		array(
    	        'key'		=> 'start_date',
    	        'compare'	=> '<=',
    	        'value'		=> $today,
    	    ),
    	     array(
    	        'key'		=> 'end_date',
    	        'compare'	=> '>=',
    	        'value'		=> $today,
    	    )
        ),
    );

    I removed all that stuff in the functions.php and just did

    $event1 = current_time(‘Ymd’) then for my array I used a key of my end date field compare to greater than $event1 (aka current date in Ymd).