Query post with date time range from custom field

<?php 

$sdtime = DateTime::createFromFormat("d F, Y", '1 February, 2018');
$edtime = DateTime::createFromFormat("d F, Y", '30 February, 2018');

$startday = $sdtime->getTimestamp();
$endday = $edtime->getTimestamp();
 
$q = new WP_Query(
    array(
    	'posts_per_page' => $count, 
    	'post_type' => 'fixture-item',
    	'meta_key'       => 'date',
		'orderby'        => 'meta_value',
		'order'          => 'DESC',
		'meta_query' => array(
			array(
				'key'       => 'date',
				'value'     => array( $startday, $endday ),
				'compare' => 'BETWEEN',
			),
		),
    )
); 

?>

Leave a Reply