I have a custom post type for events with a custom field named event_start_date, and I want to sort the archive loop according to the nearest event_start_date. In other words, the event with the nearest event_start_date to today should be displayed first.
The SQL query for this would be
ORDER BY DATEDIFF(event_start_date, NOW()) ASC. But I don't really know how to get this to work in wordpress.
I'm a completely new WP developer, and I've already tried playing around with the args for WP_Query. It only allows me to order by event_start_date which sorts the events as earliest date first, which is not the same as nearest date first.
So is it possible to order a custom field of type DATE according to the difference in date/time from today? If it is how can I do it?