Dave McCourt thinks some thoughts...

Meta query between two dates

Posted in: Code snippets, WordPress

For limiting posts to a date range (where dates are stored as custom fields)

<?php
$ad_args = array('post_type' => 'custom-post-type', 'posts_per_page' => 50,
   'meta_key' => 'expires_date',
   'meta_query' => array(
        array(
        'key' => 'starts_date',
         'value' => date('Ymd'),
         'compare' => '<='),
        array(
        'key' => 'expires_date',
        'value' => date('Ymd'),
        'compare' => '>='
       )
     ),
     'orderby' => 'meta_value_num',
     'order' => 'ASC'
 );
?>