Home › Forums › General Issues › Sorting using ACF Date field › Reply To: Sorting using ACF Date field
John, thank you for the tips, but I think my knowledge is too little. Is it more or less like this?
$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' => 'DESC',
'event_past' => 'ASC',
)
);
$query->set('order', 'ASC');
I have no ideas anymore and I am broken 🙁
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.