Try this WP_Query
arguments:
$args = array(
'post__in' => $all_ids,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => '_event_date',
'compare' => 'EXISTS',
),
array(
'key' => '_event_date',
'compare' => 'NOT EXISTS',
'value' => 'dummy_value' // This is just to ensure this condition gets evaluated.
)
),
'orderby' => array( 'meta_value_num' => 'DESC', 'date' => 'DESC' ),
'order' => 'DESC',
);
Related Posts:
- Sorting posts by custom date fields (non standard date format)
- Order posts by date and then by custom field
- Revolution Slider Orderby Two Custom Fields
- Order Posts by meta value AND published date
- Understanding the orderby in WP_Query?
- Order by empty custom field
- meta_value_num not ordering all items
- Sorting posts by Multiple custom fields in defined order
- Order 2 meta_queries differently in WP_Query?
- Order Custom Field by Price
- query_posts with sorting on a custom datestamp
- WP_Query sort by ACF date field (newest first) with blank dates first
- Can wp_query return posts meta in a single request?
- WP_Query orderby date not working
- compare meta_query in get_posts arguments
- Order by DESC, ASC in custom WP_Query
- Function in array as arguments for WP_Query
- Secondary Sort (fallback) for WP_Query
- Query Posts in a Predefined Order
- WP_Query to show post from a category OR custom field
- Getting attachments by meta value
- meta_query where value is equal to given value
- 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?
- Order by meta_value_num DESC and meta_value ASC on WP 4.0
- Order posts ascending with number in title
- List taxonomy terms plus their latest post ordered by post date
- WordPress altering my custom query, How to fix it?
- Order by meta_key in custom post type doesn’t affect the query
- How to use order RAND() on WordPress?
- Filtering posts by custom field value not working
- getting posts and number by specific meta value in multiple meta
- WordPress WP_Query orderby being overwritten
- How can I pick a single post from the latest 3?
- How do I sort posts with multiple pages
- wp_query add arguments using array_push if variable met
- Order WP_Query by multiple fields, subtracting them from one another
- pre_get_posts order by not working
- Group WP_Query by meta_key date
- How To Fix WP Query Returns Results But Shouldn’t?
- Get posts for which a custom field is not present, with get_posts
- Output an array of terms for a ‘tax_query’ => array()
- How to Filter Posts by Custom Fields?
- WP_Query order result by date AND meta_value
- Order by title without taking into account ‘the’
- WP_Query orderby author__in
- Fetch Record based on meta key dates
- Orderby is working with one query but not with other
- Weird orderby => post__in issue
- Adding multiple meta_key fields as orderby options to a WP Query via a function
- How to order posts by title after they have already been sorted by category
- WP Group posts by year(desc) > month(desc) > date(asc)
- wp_query get data from advanced custom field in wordpress
- WP Query – order posts by meta field first and then order the rest
- WP_Query Meta_key is text value and need to sort as numeric not working
- filter wp_query result with custom field values
- Having Issue on Ordering CPT by Custom Field In Custom WP Query
- Order is breaking wp_query
- WP ForLoop to compare meta information of posts to determine what post to display
- Retrieve select tag custom values from array and display them in current page with wp_query?
- How to use a dropdown to filter posts by custom field
- Querying a large number of posts including their custom fields data
- add_query_arg to compare and display events from a certain date
- Orderby two meta fields not working
- Query multiple post types, but different order for each
- Order by the first array within a meta_query
- Query ACF relationship field – Comparator IN – Value array
- How to _GET multiple value checkbox WP_Query in Custom Toxonomy / Custom Fields
- How do i create a custom post query when the meta value is an array?
- WP Query – grouping posts by same meta key, adding together values from another key
- Retrieve all custom field values of a specific custom field metakey as an array, inside WP_Query
- Custom order of posts in wp_query and different taxonomies
- WordPress Query custom ordering by temporary variable
- Comparing Meta Field date in WPQuery using Meta_Query?
- Custom order revolution sliders post base slides as inserted in Specific Posts List field
- Query Order By Number Variable From API
- How to get_comments() ordered by date and parent?
- using custom meta user data to run queries in WordPress
- Order posts by title and custom field value?
- Order & Orderby clause not working with custom query
- List users by Year of Birth using a foreach loop to dynamically populate years and data
- Meta key in wp_query bug?
- Wrap group of wp query posts to parent div by date/year
- Using custom field as ‘orderby’ value causing post grouping by publish date
- Sorting posts by meta values: 2 different orders
- Sorting Posts with meta value not working
- Order by three custom fields (Y-m-d), then separate into yearly sections
- Show sticky post before other WP_Query
- Custom query to order by multiple taxonomies
- Sorting: custom query with orderby meta_value_num THEN by title
- orderby in WP_query doesn’t works
- 404 on Pages for Custom Post Type & Query_Posts
- Order by meta values
- orderby and order filter in get_posts or WP_query function in wordpress not working
- Get posts by meta value except one post [closed]
- Why does wp_query only display the most recent post when using order ASC?
- Best performance for use Custom Field in WP
- How to include custom fields in wordpress search
- Extend search query to search meta keys values based on search string
- new WP_Query with order args – no more distinction between categories