This cannot be done via WP_Query
, the orderby
parameter can take multiple values, but those are telling it what to order by, aka date, time, title, etc These are the valid values
You can specify that it must order by post meta, but you can’t specify more than one post meta, because it uses the meta defined in the meta_key
option, which does not take an array, and can only have a single value
To do this you will need to use raw SQL, and even then it may not be possible with a single query
On top of that, this query is extremely expensive and slow, doing this will make it even slower.
As an aside, switching _stock_status
to use a taxonomy instead of post meta, would provide a big speed up on any queries that use it. Never store something in post meta if you need to search for it or list everything with that key/value pair. That’s what taxonomies are for.
Related Posts:
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Query WooCommerce orders where meta data does not exist
- Order by two meta keys
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- WP Query – Get WooCommerce Products with variation that is in stock
- How to get user_id from wordpress database inside ajax function?
- pre_get_posts filter meta_query without conflicting existing meta_query
- Extending woocommerce admin product search
- pre_get_posts order by not working
- Single meta_query query using OR instead of AND in request’s WHERE statement
- Display posts from only one post form in custom query and exclude in main query
- Using meta_query with multiple keys and compare values
- Extend product search with meta in WooCommerce
- Help ordering Post loop by two meta values
- Order ascending is ignored in meta query?
- meta_query not working as expected
- New WP_Query calls Pre_get_posts filter twice
- Woocommerce – exclude only older out-of-stock items
- Sorting search results with custom dropdown
- $wp_query->found_posts not returning correct value
- Make a products only viewable to a specific user ID in meta_query pre_get_posts
- ElasticPress is (aparently) messing with my search filters
- Woocommerce Get Orders By Meta Value
- meta_query is overriding default search
- Pre get posts sort by meta key returns no results if meta key does not exist
- Woocomerce – Order products by float attribute in archive pages
- Using the same WP_Query for shop and widgets in WooCommerce shop
- Sort posts in dashboard using custom field; also include posts where field isn’t set
- Looking for a way to exclude frontpage and nav menu from query filter
- Variations as Single Products [closed]
- How to get products with the same custom attribute like ean code
- Is it possible to set specific posts to show first in a query?
- how to make members list directory through wordpress post custom meta key.
- WooCommerce – get product sub categories
- hide custom post types with specific meta key ON admin backend
- WP_Query ignoring tax_query when is_singular
- Having trouble with WooCommerce Storefront child theme single.php “related posts” modification [closed]
- Modify wp-query and sort by post meta key
- Tax query AND/OR meta query [duplicate]
- wordpress search word, “hello world” ===> ‘hello+world’ ===> ‘hello’, ‘world’
- Order by meta value (numeric value lower to higher)
- Woocommerce – Changing the order of the upsell products [closed]
- Out Of memory issue on post per page parameter
- Changing sort order for presentation by Jetpack infinite scroll
- Large AND OR query timing out
- Orderby listing issue
- Applying posts_clauses filter to specific queries only
- Filtering out child category posts from parent category archive not working
- Display most popular in the past two days
- WP_Query with different postmeta filter for each categories
- get posts by meta_key from inside key of post meta
- Help optimizing slow WP_Query with meta_query
- meta_value_num not ordering all items
- Slow WP_Query with ‘OR’ on meta_query
- Meta Queries – should nesting work after WP 4.1?
- Filter and Order by Multiple Custom Meta Values
- Meta Query relation “AND” then set array accordingly
- Configuring a meta query with multiple post types that have the same relationship on a single page
- 2 weeks ago from meta query meta value
- WP_Query with meta_query dosen’t return results
- database query with more than a couple meta hangs and doesn’t complete
- How to filter a query by multiple meta keys and order by other meta keys
- meta_compare not comparing whole integer
- Shouldn’t I be able to modify the main query by this filter?
- Redirect to another page using contact form 7? [closed]
- Query posts with “non set” meta value
- how to access query string in wordpress?
- How Can I Change The Tax Query For The Main Loop For Taxonomy Archives?
- using pre_get_posts for search results not found
- Make meta query treat meta_value as 1 or 0
- Query with meta_query and tax_query together not working properly
- wp_query not working with post_type
- Array as ‘key’ in WP_Query
- Hide elements outside loop based on query
- Ordering a mysql style datetime stamp with meta_query
- Merge two search functions for custom post type
- Need Sub-category with main Category
- Is it possible to query a custom field where the value is between two fields?
- Woocommerce pagination and result count after custom loop
- How to query woocommerce product by pricing? [closed]
- WP Query – order posts by meta field first and then order the rest
- Meta Query doesn’t works as espected
- pre_get_posts – Trying to get property of non-object warning
- Make a SQL query with wpdb in WordPress
- Filter posts by comparing custom meta value against postdate
- How to provide meta_key array to wp_query?
- Wp_query with 2 meta keys and array of meta values
- Advanced WP_Query with meta_query, orderby?
- meta_query: check if number exists
- how to use pre_gets_posts to exclude one queried ID from homepage loop
- How to order WP_Query to group results?
- Searching for meta_key returns 0 posts
- Error with function in functions.php?
- Event with multiple dates, display events chronologically
- meta_query fails to compare on values containing apostrophes
- meta queries do ‘either/or’ checks
- How to set up hierarchical relationships without using plugins / meta query
- WP Query ordering on a meta field for posts with a date in the future not ordering by datetime
- Can’t fetch Custom Post Type Data through Custom Query