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]
- compare meta_query in get_posts arguments
- Display products from specific category in shop page
- How to uniquely identify queries?
- Query by meta_key and order by meta_value_num return orderby date
- Function to check if author has posted within the last x days
- Wp_query order by multiple custom fields?
- Single page theme that uses pages for the content
- Display featured products through custom loop in WooCommerce 3 [closed]
- Get product list of given category
- How to exclude products by tag from woocommerce shop page?
- Multiple meta queries but arrange by specific meta value order
- When querying a combination of posts and other meta fields, is there a better solution than directly modifying the WHERE value?
- Order Posts by meta value AND published date
- WooCommerce Only OnSale Products Loop Snippet [closed]
- What format does the meta_query TIME type require?
- Formulate a url to show posts with both taxonomy terms
- merge two query arguments into one WP_Query call
- Adding a parameter to the default query
- Using WP_Query in “parse_query” or “pre_get_post” in Posts2Posts
- WP_Query filter and order by meta ordering by wrong joined table
- WP_Query last five posts, simply ordered by meta_value
- What is the random string I am seeing when I use get_query_var?
- meta_query in WP_Query value is not accepting array
- Changing sort order for presentation by Jetpack infinite scroll
- get posts by meta_key from inside key of post meta
- Help optimizing slow WP_Query with meta_query
- Filter and Order by Multiple Custom Meta Values
- Meta Query relation “AND” then set array accordingly
- 2 weeks ago from meta query meta value
- Query with meta_query and tax_query together not working properly
- Array as ‘key’ in WP_Query
- Is it possible to query a custom field where the value is between two fields?
- How to query woocommerce product by pricing? [closed]
- Filter posts by comparing custom meta value against postdate
- Searching for meta_key returns 0 posts
- meta_query fails to compare on values containing apostrophes
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- Check if searched number is within the post meta value
- WP Query / Meta Query [duplicate]
- Query posts by searching for a string in a meta field
- Query multiple post types, but different order for each
- How to add date_query to meta_query array
- Order by the first array within a meta_query
- Output product category link from WP_Query
- Query ACF relationship field – Comparator IN – Value array
- Multiple nested meta queries
- How to _GET multiple value checkbox WP_Query in Custom Toxonomy / Custom Fields
- How can I modify the query by adding to the existing query?
- Comparing Meta Field date in WPQuery using Meta_Query?
- Get categories within specific term
- Custom query for custom post type not getting correct post ID
- Filtering WP_Query based on wp_postmeta keys values
- Not able to fetch woocommerce variation sales products for particular category products
- Global page ID variable empty error
- Multiple meta_query not working
- compare for multiple meta values for same key in wp_query
- datetime picker, timestamps and meta queries
- WP_Query with meta_query won’t orderby
- meta_query only check if both value are set
- Save query in function for custom gallery
- Seach and categories not working when ignoring sticky posts in main loop
- What argument does my function need to echo get_results() query results
- Extending WP Query: Custom geolocation meta values work, but tax_query breaks
- Using custom field as ‘orderby’ value causing post grouping by publish date
- Creating Custom Query
- WP_Query by meta key not returning any posts
- 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
- How do I subquery with custom meta fields?