Home › Forums › Front-end Issues › Crazy complex Query with sorting and filtering. Totally stumped. › Reply To: Crazy complex Query with sorting and filtering. Totally stumped.
Here’s what I ended up with, and it seems to work.
$upcoming_query = new WP_Query(array(
'post_type' => 'my_event',
'numberposts' => -1,
'posts_per_page' => 1000000,
'meta_query' => array(
'relation' => 'AND',
'start_date_clause' => array(
'key' => 'start_date',
'value' => Carbon::now()->format("Ymd"),
'compare' => '>=',
),
'same_date_sort_clause' => array(
'key' => 'same_date_sort', // higher number is earlier
'compare' => 'EXISTS',
),
),
'orderby' => array(
'start_date_clause' => "DESC",
'same_date_sort_clause' => "ASC"
)
));
The same_date_sort/EXISTS clause doesn’t do anything (they all have that field), but it lets me use same_date_sort_clause/ASC for sorting below.
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.