orderby custom post type by date field not working
-
I’m trying to get all of the posts from a custom post type (‘match’), and display them in order of a custom date field (date_field – using the date picker from the Advanced Custom Fields plugin). This seemed to be working fine initially, but not anymore. Infact, sometimes it works, and sometimes it doesn’t. Mostly it seems to order the posts randomely. It’s odd and I can’t figure out what the problem is.
Can anyone see anything wrong with this code?
<?php $the_query = new WP_Query( array( 'post_type' => 'match', 'order' => 'ASC', 'orderby' => 'meta_value', 'meta_key' => 'date_field' ) ); $current_header = ''; while ( $the_query->have_posts() ) : $the_query->the_post(); # get the datum for this post $temp_date = get_post_meta( get_the_ID(), 'date_field', true ); if (strtotime($temp_date) > strtotime('now')){ if ( $temp_date != $current_header ) { $current_header = $temp_date; echo "<dt>$current_header</dt>"; }?> <dd><?php the_title();?></dd> <?php } endwhile; wp_reset_query();?>
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘orderby custom post type by date field not working’ is closed to new replies.