Copied from StackOverflow:
WP_Query
offers adate_query
parameter, allowing you to set a range with before and after.https://developer.wordpress.org/reference/classes/wp_query/#date-parameters
$args = array(
'date_query' => array(
array(
'after' => 'January 1st, 2015',
'before' => 'December 31st, 2015',
'inclusive' => true,
),
),
);
$query = new WP_Query( $args );
The above suggestion of usingSee the linked documentation for more details.
Note that the other answer, which uses a postmeta query, is really out of date, no one should do that now that WP_Query
supports these date queries.