You can only sort on 1 meta value. A few posts (including this SE answer) suggest adding a filter to change the order.
Add a function to your theme’s function.php
file that will replace the sort order:
function change_sort_order( $orderby ) {
return str_replace('wp_posts.post_date', 'mt2.meta_value, mt1.meta_value', $orderby);
}
Then use it where you want. Make sure you remove the filter after it’s used so that it doesn’t stay in effect once you’re done with it.
$args = array(
'post_type' => 'courses',
'meta_query' => array(
'relation' => 'OR',
array('key' => 'class_day'),
array('key' => 'class_start')
)
);
$the_query = new WP_Query( $args );
add_filter('posts_orderby','change_sort_order');
$loop = new WP_Query( $args );
remove_filter('posts_orderby','change_sort_order');
Related Posts:
- ACF Relationship Field Search Filtering [closed]
- ACF datepicker meta_query Compare Dates in m/d/Y g:i a – Not in Ymd Format
- meta_query with array as value
- If two first numbers exist in wp_meta_query value
- WP_Query meta_query >= date
- ACF Date Based wp_query
- Custom query based on meta key – Reduce three states to two in results?
- What is the random string I am seeing when I use get_query_var?
- Any number in meta key (wp query)
- WP_Query with meta_query dosen’t return results
- Custom query filter by ACF date custom field
- Order WP_Query by meta_key priority when ‘OR’ relation used for multiple meta values
- ACF: How to query for a given value count of an array like field? (e.g.: How many rows has a `flexible_content` field?)
- WP_Query, ACF field and array
- Pre get posts sort by meta key returns no results if meta key does not exist
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- Get posts meta_query by repater field
- How can I modify standard search query to include also ACF custom fields values?
- Get posts using multiple values from ACF checkbox as meta query wordpress
- How do I subquery with custom meta fields?
- Use value from meta key array for use in WP_Query
- Meta_query compare operator explanation
- Nested meta_query with multiple relation keys
- meta_query ‘compare’ => ‘IN’ not working
- Sorting: custom query with orderby meta_value_num THEN by title
- Display List Of Posts Containing a Relationship Field Value [ACF]
- Using OR conditions in meta_query for query_posts argument
- WP_Query with checkbox meta_query
- Meta Query with date and time on the same Day before given time
- How to grab metabox value in wp_query meta_query key
- Is “orderby” in WP Meta Query conflicting with Meta Query?
- WordPress meta_query and order by custom field
- How can I create a WP_Query that returns posts where one meta_value
- WP Meta Query for some meta (array) values
- Sort users by meta_value_num
- How to count data records in wordpress which have same meta_value in wp_postmeta table?
- Meta_query with or without value
- Query Posts depends on custom field inside repeater field using acf
- wp_query not searching with apostrophe
- Add condition of user capability in WP_query
- How to make Meta Query case sensitive?
- How do I run through a WordPress loop called from a filter function?
- How to display multiple custom fields with the same meta_key in an ascending order?
- Meta_query with multiple keys and multiple values
- Is it a good idea to improve meta query performance by adding tax query?
- How to Union two different conditions in one WP_Query
- Modify wp-query and sort by post meta key
- Orderby listing issue
- Multisite wp_query & switch_to_blog issue
- Get all fields inlcuding “ACF” (Advanced Custom Fields) columns in wp_query
- Make meta query treat meta_value as 1 or 0
- Is this meta query problematic?
- WP Query Meta Value – How To Identify Specific, Unique Values?
- Order by meta_key doesn’t work
- Appending to existing WP_Query’s meta_query if exists
- Multiple meta_key ordering with pre_get_posts
- Error in meta_query not get result
- Meta query with compare by more than 2 fields
- How to get current page nearest parent id?
- meta_query with array as value with multiple arrays
- Why doesn’t my WP Meta Query return any results?
- WP_Query meta compare must include ALL array values
- meta_query returning excluded result
- WP Query orderby ACF boolean values and ACF field value
- Optimising WP_Query with ACF Fields
- meta_query weird behaviour, static int will work, but not user data
- Creating a query that get all posts but places meta items first
- WP_Query – display posts by custom field and order by another
- get_posts query is taking about 40 seconds to execute
- wp query to use both author id and meta_query
- Excluding posts from search results page with meta query not working
- meta_query – check for multiple meta values in key which holds an array of values
- WP_Query for a taxonomy value OR a custom post type meta field
- Searching for a specific month in a metadata saved as Timestamp (Wp_Query)
- Query for getting posts with their custom fields data in WordPress
- Meta query orderby meta_value_num sorting by role first
- How to rearrange posts based on input field values added by WordPress “Advanced Custom Fields”
- WP Query with meta queries
- Get posts having meta value between two numbers
- How to set meta_query if get_post_meta returns nested array for that key? [duplicate]
- Query by meta value (add a dropdown of all values)
- ACF: using two loops, the_field returns field content from another loop
- meta_query is not allowing to show posts when querying multiple arguments in a WP_Query
- Speed up WP_query with meta comparing dates
- Meta Query if Values Don’t Exist
- How to show all the associated posts with specific date of data metabox?
- Object of class WP_Query could not be converted to int inside shortcode
- WP_Query returns empty if meta_query has more than 7 values
- Is it possible to search for a string in posts OR postmeta?
- WP_Query Posts by Metadata from Option Tree
- WP_Query within save_post doesn’t include the item that triggered the action?
- Using orderby with 2 meta keys
- Passing conditional arrays to WP_Query() [closed]
- Query posts filter not working
- Custom query (author is post_author or meta co_author) with Pagenavi pagination
- Display all custom meta field values from the database using ACF Repeater
- Get all user with both meta_value
- How to get all post_id and meta_value using meta_key in wp_postmeta table
- WP Query – Show custom posts only if user contain some user meta
- WP_query shortcode inside acf Repeater breaks the repeater loop