I have a custom field which stores a date in a timestamp. I want to run a query that display posts based on the month, for example all entries from March, the specific day or year doesn’t matter. I’m guessing i need to use the DATE or the DATETIME type for the meta query, but i don’t know how to proceed:
if ($_GET['month']) {
$meta_query[] = array(
'key' => 'event_start_date',
'value' => $_GET['month']
);
}
$args = array(
'post_type' => 'event',
'paged' => $paged,
'posts_per_page' => -1,
'tax_query' => $cleanArray,
'meta_key' => 'event_start_date',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query'=> $meta_query
);
$events = new WP_Query($args);
You need the 2 digit month number that you want to query on and then use the code below. This should be easy with php (for example, see this post). In the code below
$month
is the number of the month in a 2 digit format, eg March would be 03.For Date Time just add eg.
00:00:00 - 23:00:00
WordPress 3.7 introduced the
date_query
to display posts by month: