I have currently a small problem understanding with meta-queries by WordPress. Initial situation:
A Custom Post Type with 2 meta-Fields (offer_start-date, offer_end-date) The CPT is intended as an offer, which should be displayed in the specified time period (between start-date and end-date) . The date here is formatted in german format DD.MM.YYYY. For that I use currently following query:
$args = array(
'post_type' => 'offer',
'posts_per_page' => -1,
'post_status' => 'publish',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'offer_start-date',
'value' => date( 'd.m.Y', time() ),
'type' => 'numeric',
'compare' => '<='
),
array(
'key' => 'offer_end-date',
'value' => date( 'd.m.Y', time() ),
'type' => 'numeric',
'compare' => '>='
)
)
);
new WP_Query( $args );
Unfortunately, the query does not yield reliable results. I can not even say 100% why. On some days all offers appear, on other days there are no offers.
I have also tried to find out the cause of the problem in the Codex, but it seems I am a strong blockhead.
If you need tu use between just use like that:
This below solution may be handy to someone