You should be able to name and sort your meta query clauses like this:
$meta_query = array(
'relation' => 'OR',
'foo' => array(
'key' => 'expiring_date',
'value' => date('Ymd'),
'compare' => '>',
'type' => 'DATE'
),
'bar' => array(
'key' => 'expiring_date',
'compare' => 'NOT EXISTS'
),
'baz' => array(
'key' => 'expiring_date',
'value' => ''
),
);
$query->set( 'meta_query', $meta_query );
$query->set('meta_key', 'expiring_date');
$query->set('orderby', array(
'foo' => 'ASC',
'bar' => 'DESC',
'baz' => 'ASC',
'title' => 'DESC'
));
More information can be found in this introduction post.
Related Posts:
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- How to get order of posts?
- Order posts by ID in the given order
- pre_get_posts with get_posts
- How-to exclude terms from the main query the most performant way?
- How to order posts tag by tag?
- “pre_get_posts” firing on every query
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- Show all parents and children in custom post type in right order
- WP_Query Order by Specific Post ID First
- How to change posts order on Category and Tag archives?
- pre_get_posts order by not working
- Show Sticky Post at the top but do not show again in the loop?
- Can I set my WP_Query to be a Main Query?
- Show scheduled posts in main loop but not in WP_Query?
- Order by empty custom field
- How to order posts by title after they have already been sorted by category
- Help ordering Post loop by two meta values
- Order ascending is ignored in meta query?
- Child pages not affected by orderby
- Filtering by multiple conditions in the loop
- WP_Query orderby random do not repeat infinite scroll – one loop
- Can I alter the main loop to ‘orderby’ a custom callback?
- How to order posts, that have already been filtered by custom taxonomy, by their category names?
- Display three sequential posts on each page load, without repeating previous
- Order posts by custom column using pre_get_posts
- Order by multiple meta keys on wordpress
- How to put posts with some taxonomy on top of others in `pre_get_posts`
- When to use WP_query(), query_posts() and pre_get_posts
- Should I use Pre Get Posts or WP_Query
- Can I force WP_Query to return no results?
- Using pre_get_posts with WP_Query
- Resetting post data to previous loop in nested loops
- Some doubts about how the main query and the custom query works in this custom theme?
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- Get post count of current loop when using multiple queries on one page
- Multiple WP_Query loops with Pagination
- Using a custom WP_Query with get_template_part loop
- WP_Query orderby date not working
- WP_Query vs get_posts
- What is “main query”? [duplicate]
- Order by optional meta key?
- Sorting: custom query with orderby meta_value_num THEN by title
- Loop within a loop?
- Order by DESC, ASC in custom WP_Query
- WP_Query and next_posts_link
- WP_Query order by multiple meta keys & fields
- Show posts without term
- Usage of the new “posts_clauses” filter in WordPress 3.1?
- Display products from specific category in shop page
- How to list some posts first in the loop based on post id
- Reduce or prevent calling of update_meta_cache
- How to add taxonomy filter on the query fly?
- Pagination returns 404 after page 20
- Make loop display posts by alphabetical order
- WP_Query: query posts by ids from array?
- Use WP_Query with have_posts()?
- Secondary Sort (fallback) for WP_Query
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Query Posts in a Predefined Order
- get custom post type by tag
- How to uniquely identify queries?
- Order Search Results Page by meta_value If no Value Return Remaining Results
- Custom WP_Query order by post_meta and (author) user_meta
- Sorting posts by custom date fields (non standard date format)
- Too slow when using both ‘tax_query’ and ‘meta_query’ both in WP_Query
- get_template_part in for loop
- Get array of posts from the current archive page loop
- Pagination with WP_Query is buggy – working for some pages, but not the others
- Get the number of posts from the current page results
- How do I reorder (pop and push) items from WP_Query?
- Changing Posts Per Page and offset with pre_get_posts
- How to exclude latest x posts from a paginated query?
- Executing Queries in tag.php
- Display posts the match taxonomy term linked from wp_list_categoies?
- How can I save an array from a random post sequence for later use?
- How to place a loop within another loop?
- WordPress Custom Query to show posts from last x years
- Slow SQL_CALC_FOUND_ROWS Query
- Query Custom Meta Value with Increment
- How do I order pages and categories by ID or name in the same query?
- Show two random posts from custom post type
- RSS feed with specific keyword
- Add the “active” class only to the first loop item in a WordPress query [closed]
- Loop through all tags & output posts in alphabetical list
- Pagination with 5 posts per page
- Reverse chronology of post listing
- Identify which loop you are hooking into; primary or secondary?
- Using is_main_query to select custom post type on certain page
- WP_Query ordered by custom field that is a date string?
- In loop: posts have thumbnail AND other variables
- Multiple orderby parameters in pre_get_posts() action
- Group posts by custom field
- WP_Query sort by comment meta data
- WordPress Number of Posts Not Changing With posts_per_page
- How to order category.php loop by ‘meta_value’?
- SQL Statement generated by WP_Query not producing expected results
- Pagination/infinite scroll with WP_Query and multiple loops
- Order posts by tags count?
- Merging a complex query with post_rewind and splitting posts into two columns