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
- How to do a meta query using REST-API in WordPress 4.7+?
- Meta query terribly slow
- ORDER BY custom field value
- Sorting: custom query with orderby meta_value_num THEN by title
- meta_query sorting by 2 keys
- Get result from meta_query() between two numbers
- How to handle optional end date in compare clause in meta_query
- Using meta_query on pre_get_posts to exclude a particular meta_key value
- Custom WP_Query order by post_meta and (author) user_meta
- Query between two meta keys
- Ordering posts having multiple post-meta date fields
- Archives for custom post type based on a “date” meta value
- How to check a single number value against an array of meta_key values?
- get_users meta_query
- Meta query with multiple logic (AND / OR)
- Order Posts by Taxonomy and Meta Value
- Best practice – Meta Query vs. post_clauses for “left join” ordering
- Meta query interfering with orderby relevance
- meta_query with multiple values
- WP REST API: Order posts by meta value (acf)?
- Different page parameters inside query
- 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
- meta_query key value from array
- Is there a way to do multiple ordering on a multiple meta_query?
- LIKE %…% Meta Query
- Multiple Values stored as array in Meta Query
- Documentation for post meta
- How to order a post type with meta_value_num and if meta_value_num does not exist then order by date
- Advanced orderby with multiple meta_query
- Using get_terms() with meta_query parameters
- WP_User_Query with meta_query array relation ‘OR’
- Ordering posts by anniversary using only day and month
- query order by date on custom type: wrong order
- meta_query problem
- Custom Upcoming Events List for Events Manager Plugin
- Very slow query with meta_query on large database
- How to use meta_query to check if a meta field has something set?
- How to exlude posts that have certain meta_value?
- Order WP Query posts by custom order calculated from post meta values
- Display custom post types with custom date field value (before today) & order by custom date field
- User Relationship
- Sorting posts by multiple values, combined
- Order by meta_key with two meta_queries
- meta_query results not the same with and without spaces
- Meta query with order by another custom field
- meta_query all posts between to ages
- How to make a WP REST API query with meta_query in WP4.7?
- List of posts by day of the week
- sort by date in Advanced Custom Field
- WordPress Core – Optimizing meta_query generated SQL?
- Order Posts by meta value AND published date
- Edit post_content on posts with Featured Image
- Sorting posts by custom fields in meta_query
- Nested Queries using meta_query
- Display no post when metavalue is 0
- Use both meta query and tax query
- Wildcard with LIKE operator in Meta query
- meta_query, number comparison, not quite working as it should
- Meta Query Compare with Date
- Query posts only if meta_value is not empty
- Complex Orderby Parameters: How to query with multiple orderby parameters using meta_value_num?
- pre_get_posts order by not working
- Does meta_query working with value paramater higher then 999?
- meta_query keys and sticky posts
- Display post in order of ACF checkbox?
- How to pass user meta_key and meta_value (values as array)
- SQL: What is wrong with the following query (generated by WordPress WP_Query, ordering prices)
- Query Multiple values for same key
- Comparing a field with several values at once with meta_query
- Meta query with a sub query group possible?
- meta_query compare=’!=’ with multiple custom fields
- Query posts with numeric meta values within a given range
- Fastest way to do meta query when I don’t need the actual posts, and just need post_id?
- meta_query not working on live site
- How to orderby multiple meta fields if some fields are empty
- How to query post only with different excerpt?
- How do you get Posts by multiple meta_keys and meta_values with the Rest API V2?
- Query custom field with date
- How to do WP_Query with two meta fields with orderby clause
- Meta query with regular expression does not work
- Searching in title or meta, with a tax query too!
- WP_Query with meta_query no results
- Documentation for post meta
- Help ordering Post loop by two meta values
- Order ascending is ignored in meta query?
- Alter main archive, to show posts with meta as last
- WP User Query Issues