I have the following code where I want to sort by meta key "event_date" and only display posts after todays date and 3 weeks ahead. Somehow nothing happens, even when I'm stripping down the WP Query to just post type and order, nothing gets printed ud, the scripts just dies where the code is inserted.
<?php $events_args = array(
'meta_query' => array(
array(
'key' => 'event_date',
'value' => date('d-m-Y', strtotime("+3 weeks")),
'compare' => '<',
'type' => 'DATE'
)
),
'posts_per_page' => 3,
'post_type' => 'event',
'meta_key' => 'event_date',
'orderby' => 'meta_value',
'order' => 'ASC'
); ?>
<?php $upcoming_events = WP_Query($events_args); ?>
<?php if($upcoming_events->have_posts()): while($upcoming_events->have_posts()): $upcoming_events->the_post(); ?>
<a href="<?php the_permalink(); ?>"><article class="post_block">
<h2><?php the_title(); ?></h2>
<p class="date"><?php $date = new DateTime(get_field('event_date')); echo $date->format('d-m-Y'); ?><?php // echo get_the_date('d-m-Y'); ?></p>
<p class="text"><?php echo get_the_excerpt(); ?></p>
</article></a>
<?php endwhile; endif; wp_reset_postdata(); ?>
Any idea why nothing gets output? If I run a simple query_posts like:
query_posts('posts_per_page=3&post_type=event&meta_key=event_date&orderby=meta_value&order=DESC');
then it will print out the events, but it will sort after the newest events, and I need to sort on events from today and 3 weeks ahead to display only.
yyyy-mm-dd
to sort by date.