I don’t think this is doable in a single WP API query. You just don’t sort whole set with single logic, you have logic changing halfway. I don’t think even SQL can express this.
It is hard to advise without seeing specific circumstances (such as counts, pagination involved and so on), but my first thought would be to split this into two queries:
- “Future” posts (meta query for date field in future, order by title)
- “Past” posts (meta query for date field in the past, order by title)
Related Posts:
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- WP_Query orderby date not working
- Sorting: custom query with orderby meta_value_num THEN by title
- Order by DESC, ASC in custom WP_Query
- Secondary Sort (fallback) for WP_Query
- Query Posts in a Predefined Order
- Custom WP_Query order by post_meta and (author) user_meta
- How to order posts tag by tag?
- How do I order pages and categories by ID or name in the same query?
- WP_Query ordered by custom field that is a date string?
- WP_Query sort by comment meta data
- Order posts by tags count?
- WP_query ‘orderby=none’ Problem
- Order posts by date and then by custom field
- How to order a post type with meta_value_num and if meta_value_num does not exist then order by date
- Order posts ascending with number in title
- List taxonomy terms plus their latest post ordered by post date
- Order by the results of a function with WP_query
- How to order posts in wp_query by a meta_value of the corresponding author
- Order by menu structure
- WP_Query order by date in meta_value
- How to use order RAND() on WordPress?
- Show all parents and children in custom post type in right order
- Ordering by meta_value AND date NOT WORKING with wp_query
- WP_Query orderby breaks when using AJAX?
- Order WP Query posts by custom order calculated from post meta values
- Meta query with order by another custom field
- Change default ordering of taxonomy terms – pre_get_terms
- WordPress WP_Query orderby being overwritten
- Order Posts by meta value AND published date
- How can I pick a single post from the latest 3?
- Wp query orderby ‘title’ doesn’t work
- How can I order Wp_Query hierarchically?
- How do I sort posts with multiple pages
- Order WP_Query by multiple fields, subtracting them from one another
- pre_get_posts order by not working
- (Solved) WP_Query ($ args) -> How to sort letters and numbers within the same array
- SQL: What is wrong with the following query (generated by WordPress WP_Query, ordering prices)
- Order By table field comment_status in WordPress > 4.0
- Complex WP_Query order request: DESC by day, but then ASC by time
- WP_Query order result by date AND meta_value
- Order by title without taking into account ‘the’
- WP_Query orderby author__in
- How to orderby multiple meta fields if some fields are empty
- Sort wordpress custom posts based on meta value
- WP_Query: Group events by year, sorted DESC; then by date for each year group, sorted ASC
- Weird orderby => post__in issue
- Order by summing multiple values
- Understanding the orderby in WP_Query?
- How to order posts by title after they have already been sorted by category
- Order ascending is ignored in meta query?
- How to filter a query by multiple meta keys and order by other meta keys
- Multiple Orderby’s using random order WP_Query
- Debugging wp_query orderby for taxonomy
- WP Query – order posts by meta field first and then order the rest
- Ordering posts by an array
- Advanced WP_Query with meta_query, orderby?
- How to Order a list of taxonomies? orderby?
- Order is breaking wp_query
- WP_Query with multiple orderby NOT working with ASC and DESC, what’s wrong?
- Filtering by multiple conditions in the loop
- Orderby two meta fields not working
- Randomly select one of last 3 posts
- WP_Query orderby random do not repeat infinite scroll – one loop
- how to retrieve WP_Query without ordering by date [duplicate]
- orderby ignored by wp_query
- WP_Query orderby
- What’s wrong with this meta query? (order by meta key, then title, doesn’t work)
- How can I order a post query’s results based on the number of matching taxonomy terms?
- How to sort store location by specific category order in WP store locations
- Custom WP Query order function possible?
- Custom order of posts in wp_query and different taxonomies
- WP_Query random ordering not working since 5.4
- WordPress Query custom ordering by temporary variable
- Meta query orderby meta_value_num sorting by role first
- Order by value of Custom Field using url string
- Order by meta date with a thousanth of a second defaults to post order
- WP Query with meta queries
- How to get_comments() ordered by date and parent?
- Sorting with meta_query and multiple, optional meta keys
- WP Query. Ordering posts by another post types meta
- Best way to query posts and order by relevancy to query
- How to order posts, that have already been filtered by custom taxonomy, by their category names?
- wp_query sorting – one specific meta_key value at last and then sort by create date
- query_posts based on a meta_key
- Display three sequential posts on each page load, without repeating previous
- Order posts by more than one variable (meta_key and publish date AND time)
- Create custom order sortby based on array of id
- Sort by meta key within same day
- Find by post_meta, then sort by post_meta, then sort by date (wp_posts)
- Order Custom Field by Price
- Show sticky post before other WP_Query
- query_posts with sorting on a custom datestamp
- Order by multiple meta keys on wordpress
- WP_Query with several meta_query-statements and order by meta_value
- Get posts that were most recently tagged
- Why does wp_query only display the most recent post when using order ASC?
- WP_Query sort by ACF date field (newest first) with blank dates first
- new WP_Query with order args – no more distinction between categories