Home › Forums › General Issues › Sorting using ACF Date field › Reply To: Sorting using ACF Date field
Thank you very much for your answer.
Eventually I’m done with the code below:
$now = date('Y-m-d H:i:s');
$meta_query = array(
'meta_query' => array(
'relation' => 'OR',
array(
'event_start' => array(
'key' => 'start_date',
'compare' => '<',
'value' => $now,
'type' => 'DATETIME'
),
'event_end' => array(
'key' => 'end_date',
'compare' => '>',
'value' => $now,
'type' => 'DATETIME'
),
),
array(
'event_upcoming' => array(
'key' => 'start_date',
'compare' => '>=',
'value' => $now,
'type' => 'DATETIME'
)
),
array(
'event_past' => array(
'key' => 'end_date',
'compare' => '<',
'value' => $now,
'type' => 'DATETIME',
),
),
),
);
$query->set('meta_query', $meta_query);
$query->set(
'orderby',
array(
'event_start' => 'DESC',
'event_end' => 'DESC',
'event_upcoming' => 'ASC',
'event_past' => 'DESC',
)
);
$query->set('order', 'DESC');
And I was able to get that order:
1. ONGOING EVENTS
2. PAST EVENTS
3. UPCOMMING EVENTS
Is it not possible to use WP_Query for PAST EVENTS to be last?
Are there any other ways?
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.