I’m trying to order my upcoming events by custom post meta date, but it’s not working as it should. It orders by days only and ignores months and years.
example:
1st April 2016
4th July 2016
10th May 2016
<?php
global $post;
$today = date('jS F Y');
$args = array(
'post_type' => 'event',
'posts_per_page' => 4,
'meta_key' => 'start_date',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_value_num' => $today,
'meta_compare' => '>'
);
$loop = new WP_Query( $args );
echo '<ul class="events-list">';
while ( $loop->have_posts() ) : $loop->the_post();
echo '<li>';
echo '<div class="meta-fields">';
$start_date = get_post_meta( get_the_ID(), 'start_date', true );
$new_format_start = date_i18n('jS F Y',strtotime($start_date));
$end_date = get_post_meta( get_the_ID(), 'end_date', true );
echo $new_format_start;
if ($end_date) {
$new_format_end = date_i18n('jS F Y',strtotime($end_date));
echo ' - ' . $new_format_end;
} else {
echo "";
}
echo '</div>';
?>
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
<div class="entry-content">
<p class="event-widget"> <?php echo get_the_excerpt(); ?> </p>
</div>
</li>
<?php
endwhile;
echo '</ul>';
}
Okay apparently it didn’t work because I was using a datepicker in my input, so I changed it to
<input type="date">
.Too bad input date doesn’t work in firefox.