Home › Forums › General Issues › Query not ordering correctly by datepicker date
I am trying to order a series of pages based on a custom field value for the date.
The pages are ordering as:
July 24, 2016
January 4, 2016
April 14, 2019
I need the order to be:
January 4, 2016
July 24, 2016
April 14, 2019
This is the code in a WP Query:
'meta_key' => 'my_publish_date',
'meta_type' => 'DATE',
'orderby' => 'meta_value',
'order' => 'ASC',
I have the Display Format and Return Format to return the value of F j, Y (Month Day, Year)
I’ve tried numerous alterations to the query to affect the order, but the issue remains
Any suggestions?
No luck.
I confirmed that the date is being stored in the YYYYMMDD format within the database.
Date fields are not stored in “DATE” format which would be “Y-m-d H:i:s”. That is the only issue that I saw with your query.
That’s why I’m confused. Been working with ACF for a while and custom fields in general, but this one has me stumped.
The dates & corresponding post_ids are as follows so even if it wasn’t reading the custom field and default ordering by post ID, I’d still expect it to be in order, and the post names follow a similar hierarchy. It should be falling in the correct order regardless of the field, title, or post id.
20160724 – post_id: 2392 – “product 2”
20160104 – post_id: 2390 – “product 1”
20190414 – post_id: 2394 – “product 3”
I’m well and truly stumped. Anyone have this issue and care to share their solution or things to check?
I would look for a pre_get_posts filter that might be interfering with your query. Not always an easy task because these can be anywhere.
What’s odd is that it will work for a field with just a general numerical value. It’s just the date that’s the breakdown.
The only “pre_get_posts” filter I have is in regards to stopping empty search returns. I disabled it and the issue continues.
I’ll keep looking but this … it doesn’t make sense.
Okay, found the problem. It existed between the keyboard and chair. *head desk*
Thanks for your patience, John!
The topic ‘Query not ordering correctly by datepicker date’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.