How to do a wp_query using “BETWEEN” with two meta_values?

This should work for you:

$tEA = array(
    'post_type' => 'event',
    // you dont need meta_key as you use meta_query
    //'meta_key' => $metaKey,
    'orderby' => 'meta_value',
    'order' => $order,
    'posts_per_page' => $postPerPage,
    'meta_query' => array(
        array(
            'key' => $metaKey,
            // value should be array of (lower, higher) with BETWEEN
            'value' => array('START_DATE', 'END_DATE'),
            'compare' => 'BETWEEN',
            'type' => 'DATE'
        ),
    )
);

Note that START_DATE and END_DATE should be in MySQL date format YYYY-MM-DD

Leave a Comment

error code: 523