I built a website for a local music venue and ACF has been a massive part of that. Since everything is date-centric, in the original build, I made it so that events can be attached to certain dates (incorrectly) assuming there would ever only be one event on that day. Well, that was the way the club USED to run, but now they’ve been booking early and late shows, and sometimes mid-day community dates, so I converted the date picker to a date time picker. All was fine… until all the legacy content expired.
There’s a “past events” page, where when shows have happened, they move from the front page the past events page. They still all show up, but now they’re all out of order, showing the items with the date picker first, and then the date time picker later.
Is there a way to convert data stored as date picker to date time picker format, so all the legacy content sorts co-mingled with the new content? If you look at the past events page, it looks as if the venue stopped booking in august, but the home page clearly has new events, and if you search for events that happened last week, they’re on the past events page, just further down the page.
on the home page I’m using this query:
<?php //http://support.advancedcustomfields.com/forums/topic/sorting-events-with-by-date-picker-field/ $args = array( 'post_type' => 'events', 'posts_per_page' => -1, 'meta_key' => 'date', 'orderby' => 'meta_value', //'type' => 'DATETIME', 'order' => 'ASC' ); ?>
and on the past events page, I’m using this query:
<?php //http://support.advancedcustomfields.com/forums/topic/sorting-events-with-by-date-picker-field/ $args = array( 'post_type' => 'events', 'posts_per_page' => -1, 'meta_key' => 'date', 'orderby' => 'meta_value_num', 'order' => 'DESC' ); ?>
I feel like the data stored isn’t 1:1, so maybe I need to convert the legacy date picker data, so its the same as the date time picker data? The ACF meta key is the same ‘date’ for both the old and new data.
I’m absolutely slammed right now, the venue is trying to stay afloat during COVID and this just came up. Hoping the ACF community can point me in the right direction so I can solve this. It’s been since June or so, so the code isn’t fresh, and the issue wouldn’t have revealed itself until September, and the venue just notified me of the bug this week.
Don’t know if you figured this out yet or not but the data for these two fields are stored differently in the DB.
date field format “Ymd”
date/time field format “Y:m:d H:i:s”
If you want them to be ordered correctly then you need to update every meta value to the right format in the DB. I haven’t got any idea how that would be done.
You must be logged in to reply to this topic.
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!
© 2022 Advanced Custom Fields.