If you’re using WordPress 4.2 or newer then you can do the following:
$args = array(
'post_type' => 'products',
'posts_per_page' => 10,
'meta_query' => array(
'relation' => 'AND',
'tools_clause' => array(
'key' => 'tools',
'compare' => 'EXISTS',
),
'create_date_clause' => array(
'key' => 'create_date',
'compare' => 'EXISTS',
),
),
'order_by' => array(
'create_date_clause' => 'ASC',
'tools_clause' => 'ASC',
)
);
Take a look here:
Query improvements in WP 4.2: ‘orderby’ and ‘meta_query’
Related Posts:
- Sorting: custom query with orderby meta_value_num THEN by title
- Custom WP_Query order by post_meta and (author) user_meta
- How to order a post type with meta_value_num and if meta_value_num does not exist then order by date
- Order WP Query posts by custom order calculated from post meta values
- Meta query with order by another custom field
- Order Posts by meta value AND published date
- Complex Orderby Parameters: How to query with multiple orderby parameters using meta_value_num?
- pre_get_posts order by not working
- SQL: What is wrong with the following query (generated by WordPress WP_Query, ordering prices)
- How to orderby multiple meta fields if some fields are empty
- Help ordering Post loop by two meta values
- Order ascending is ignored in meta query?
- meta_value_num not ordering all items
- How to filter a query by multiple meta keys and order by other meta keys
- Advanced WP_Query with meta_query, orderby?
- Sort posts using multiple custom fields and menu_order in single query?
- What’s wrong with this meta query? (order by meta key, then title, doesn’t work)
- WordPress Query custom ordering by temporary variable
- Meta query orderby meta_value_num sorting by role first
- WP_User_Query Orderby Not Working
- Sorting with meta_query and multiple, optional meta keys
- WP Query. Ordering posts by another post types meta
- Best way to Order Post in Home without a plugin
- Using orderby with 2 meta keys
- Sorting: custom query with orderby meta_value_num THEN by title
- WP_Query with several meta_query-statements and order by meta_value
- Meta_query compare operator explanation
- meta_query ‘compare’ => ‘IN’ not working
- Ignoring initial articles (like ‘a’, ‘an’ or ‘the’) when sorting queries?
- Order posts by ID in the given order
- WP_Query with checkbox meta_query
- 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 date and time on the same Day before given time
- How to grab metabox value in wp_query meta_query key
- WP_Query sort by comment meta data
- Is “orderby” in WP Meta Query conflicting with Meta Query?
- Order posts by tags count?
- Orderby = none not working [duplicate]
- WP_query ‘orderby=none’ Problem
- 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
- query order by date on custom type: wrong order
- How to count data records in wordpress which have same meta_value in wp_postmeta table?
- Ordering by meta_value AND date NOT WORKING with wp_query
- WP_Query orderby breaks when using AJAX?
- Change default ordering of taxonomy terms – pre_get_terms
- wp_query not searching with apostrophe
- Add condition of user capability in WP_query
- (Solved) WP_Query ($ args) -> How to sort letters and numbers within the same array
- Custom query based on meta key – Reduce three states to two in results?
- How to make Meta Query case sensitive?
- Any number in meta key (wp query)
- How to set multiple `orderby` in query argument?
- 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?
- WP_Query: Group events by year, sorted DESC; then by date for each year group, sorted ASC
- Order by summing multiple values
- Understanding the orderby in WP_Query?
- Modify wp-query and sort by post meta key
- Orderby listing issue
- Make meta query treat meta_value as 1 or 0
- Ordering posts by an array
- 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
- Meta query with compare by more than 2 fields
- WP_Query orderby random do not repeat infinite scroll – one loop
- WP_Query meta compare must include ALL array values
- meta_query returning excluded result
- meta_query weird behaviour, static int will work, but not user data
- Creating a query that get all posts but places meta items first
- get_posts query is taking about 40 seconds to execute
- How can I order a post query’s results based on the number of matching taxonomy terms?
- wp query to use both author id and meta_query
- WP_Query for a taxonomy value OR a custom post type meta field
- Custom WP Query order function possible?
- Order by value of Custom Field using url string
- WP Query with meta queries
- How to set meta_query if get_post_meta returns nested array for that key? [duplicate]
- 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 order posts, that have already been filtered by custom taxonomy, by their category names?
- WP_Query returns empty if meta_query has more than 7 values
- orderby in WP_QUERY – Use the order from the Dashboard
- WordPress meta_query not working
- query_posts with sorting on a custom datestamp
- Passing conditional arrays to WP_Query() [closed]
- Posts2Posts, wp_query and orderby issue
- Custom query (author is post_author or meta co_author) with Pagenavi pagination
- Change posts archive ordering
- Get all user with both meta_value
- How do I have multiple metaqueries inside one wordpress query
- WP query with multiple custom meta not respecting orderby
- Display only posts with thumbnails