Title: Date order issue
Last modified: October 1, 2019

---

# Date order issue

 *  Resolved [ivyowl](https://wordpress.org/support/users/ivyowl/)
 * (@ivyowl)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/date-order-issue/)
 * I’m having an issue with the ordering of posts by date.
 * The posts are displaying correctly in ascending order day and month but they 
   are displaying 2020 dates before 2019 dates.
 * Here is the query:
 *     ```
       $args = array(
       'post_type' => 'lnb_events',
       'posts_per_page' => -1,
       'orderby' => 'meta_value',
       'meta_key' => '_lnb_events_event-start-date',
       'order' => 'ASC',
       );
       $loop = new WP_Query( $args );
       ```
   
 * The meta key is a text_date picker generated by cmb2.
 * Any help on this would be much appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [6 years, 6 months ago](https://wordpress.org/support/topic/date-order-issue/#post-11986077)
 * I would review [https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters](https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters)
   as date comparison isn’t always as easy and straightforward as one may think.
   Part of why WP core provides parameters that allow you to say ‘hey, this is a
   date that needs compared”
 *  Thread Starter [ivyowl](https://wordpress.org/support/users/ivyowl/)
 * (@ivyowl)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/date-order-issue/#post-11987129)
 * I’ve tried using meta-type date also but it also produces a random result.
 * What query would best suit the text_date to produce a asc return?
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [6 years, 6 months ago](https://wordpress.org/support/topic/date-order-issue/#post-11987333)
 * Honestly, in these cases, I’d probably end up just storing a UTC timestamp for
   the actual meta value, and then handle the formatting of the date upon output
   and whatnot. At least with timestamps, they’re numbers like “1569956490” which
   are easy to order by
 *  Thread Starter [ivyowl](https://wordpress.org/support/users/ivyowl/)
 * (@ivyowl)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/date-order-issue/#post-11988769)
 * That sounds like a good plan, what does the text_date store as as standard? And
   how do you change how it stores?
 * Also if I was to change that would I then have to reinput all the dates that 
   are currently stored?
 * Really appreciate your support.
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [6 years, 6 months ago](https://wordpress.org/support/topic/date-order-issue/#post-11989725)
 * Based on [https://github.com/CMB2/CMB2/wiki/Field-Types#text_date](https://github.com/CMB2/CMB2/wiki/Field-Types#text_date)
   it stores it in whatever the specified date_format is, and if you haven’t provided
   a custom format, then I think it’s the format shown in the example.
 * If you scroll down a little, you’ll find [https://github.com/CMB2/CMB2/wiki/Field-Types#text_date_timestamp](https://github.com/CMB2/CMB2/wiki/Field-Types#text_date_timestamp)
   as a different field type.
 * Regarding existing posts, yes I do believe you’d need to go through and update
   them to get the new field type’s saving to take.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Date order issue’ is closed to new replies.

 * ![](https://ps.w.org/cmb2/assets/icon.svg?rev=2866672)
 * [CMB2](https://wordpress.org/plugins/cmb2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cmb2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cmb2/)
 * [Active Topics](https://wordpress.org/support/plugin/cmb2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cmb2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cmb2/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * Last activity: [6 years, 6 months ago](https://wordpress.org/support/topic/date-order-issue/#post-11989725)
 * Status: resolved