The meta_key
parameter tells WP_Query
to only return posts that have the price_sale_custom
meta data. Remove that first, and then change orderby
to reference the meta_query
values:
This is something that WordPress added support for in 4.2: https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/
https://stackoverflow.com/questions/17745334/how-to-order-by-multiple-meta-keys
Related Posts:
- Order by nested named meta queries with ‘exists’ and ‘not exists’
- Arrange Posts By Date In Order Of Closest To The Current Date
- WP_Query ordered by meta_value_num doesn’t fetch posts without this meta field
- Custom post type archive with rand and meta_value
- WordPress Screwing Up ‘orderby’ => ‘meta_value_num’ in ‘pre_get_posts’
- Orderby doesn’t work like expected on custom query
- last_name + first_name orderby with meta_query [solved]
- Order resultset by configured value and then list all the rest
- meta_query check multiple date formats
- Why does this incorrect pre_get_posts meta_query work for sort order?
- Meta query array – same order as specified order in value
- Admin products page column not sorting
- Sorting: custom query with orderby meta_value_num THEN by title
- Get result from meta_query() between two numbers
- Custom WP_Query order by post_meta and (author) user_meta
- Ordering posts having multiple post-meta date fields
- Archives for custom post type based on a “date” meta value
- get_users meta_query
- Meta query interfering with orderby relevance
- meta_query with multiple values
- WP REST API: Order posts by meta value (acf)?
- Trying to perform complex custom field query with order by set to field value
- Return posts with specific meta key first, but the rest in alpha order by last name
- How to order a post type with meta_value_num and if meta_value_num does not exist then order by date
- Using get_terms() with meta_query parameters
- WP_User_Query with meta_query array relation ‘OR’
- meta_query problem
- How to exlude posts that have certain meta_value?
- Order WP Query posts by custom order calculated from post meta values
- Order by meta_key with two meta_queries
- Meta query with order by another custom field
- meta_query all posts between to ages
- List of posts by day of the week
- sort by date in Advanced Custom Field
- WordPress Core – Optimizing meta_query generated SQL?
- Display no post when metavalue is 0
- Wildcard with LIKE operator in Meta query
- Meta Query Compare with Date
- Does meta_query working with value paramater higher then 999?
- meta_query keys and sticky posts
- 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
- How to query post only with different excerpt?
- How to do WP_Query with two meta fields with orderby clause
- WP_Query with meta_query no results
- Order ascending is ignored in meta query?
- How to use meta query for greater than value in array?
- Wp Query custom search by meta query
- Filter posts by meta query?
- How to filter a query by multiple meta keys and order by other meta keys
- Ordering posts by custom field named “date” in backend
- Meta query date column add [x] days to validate
- WP Query – Is this correct?
- Advanced WP_Query with meta_query, orderby?
- I would like to have add_post_meta to return the ID instead of true or false
- Order by meta value
- Can I use pre_get_posts to add up values from two different meta_keys?
- get_users with Serialized Custom Meta Value
- Sorting posts by ACF field
- Unable to use meta_query between currency values when value is over 1 million
- latitude/longitude meta_query
- Delete all posts with a specific custom field using meta_query
- meta_query Array
- Issue with user meta_query
- What’s wrong with this meta query? (order by meta key, then title, doesn’t work)
- Sort products by Sale price and stock status
- Search for value(s) in meta field for a multi select
- How can I create a meta_query with an array of dates?
- Orderby if between two meta fields
- How to count items of meta query?
- WordPress meta query with meta serialized data array value
- Reading Content in an Array as it relates to a meta_query
- wordpress meta query with multiple meta condition causing a load on server and slows down the server..!
- WP Query. Ordering posts by another post types meta
- Trouble with calling an imploded variable in an array
- Memory Leak in Processing Large JSON file
- meta_query not filering but meta_key works fine
- Query for user roles and their skills
- WordPress search between two newmeric values with a custom post type
- like_escape notice when using LIKE in meta query
- wp_query sorting – one specific meta_key value at last and then sort by create date
- meta_query for user ID in array
- WP User Query with meta queries
- Query Posts that have or don’t have a meta_value and order by the same ASC
- WP_Query with UNIX timestamp in meta query
- Querying by meta key and value
- How to compare date in post meta value
- Which Meta Query Compare Method Should I use?
- Sort posts by post views and consider meta key
- Meta query “OR” comparison not working as expected with array
- How to output meta_key in wp_postmeta?
- WP_Query with several meta_query-statements and order by meta_value
- WP_Query orderby meta key/value suddely stopped working
- WordPress Meta Query very slow with NOT EXISTS comparison
- ACF meta_query field treated as “0” resulting in false negative search when testing ranges
- Is it possible to customize meta query in this way?
- Ordering WP_Query results by second meta_key
- How making a new search box in admin post table working on a specific column
- wp_user_query with meta_value_num for leaderboard
- WP_User_Query get_count issue with meta_query relation