Use a meta_query and set type to NUMERIC–
$query->set('meta_query', array(
array(
'key' => '_ai_price_int',
'value' => array(0, 4000),
'compare' => 'BETWEEN',
'type' => 'NUMERIC'
)
));
$query->set('meta_key', '_ai_price_int');
$query->set('orderby', 'meta_value_num');
Related Posts:
- Order resultset by configured value and then list all the rest
- Why does this incorrect pre_get_posts meta_query work for sort order?
- Admin products page column not sorting
- Using meta_query on pre_get_posts to exclude a particular meta_key value
- Meta query interfering with orderby relevance
- Multiple Values stored as array in Meta Query
- Order by nested named meta queries with ‘exists’ and ‘not exists’
- Help With issue on pre_get_posts filter in taxonomy
- Arrange Posts By Date In Order Of Closest To The Current Date
- Using get_terms() with meta_query parameters
- pre_get_posts order by not working
- Does meta_query working with value paramater higher then 999?
- WP_Query ordered by meta_value_num doesn’t fetch posts without this meta field
- Custom post type archive with rand and meta_value
- 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?
- pre_get_posts and set
- Orderby doesn’t work like expected on custom query
- last_name + first_name orderby with meta_query [solved]
- Can I use pre_get_posts to add up values from two different meta_keys?
- Fetch custom post related to a User
- How to Ordering by user meta
- meta_query Array
- Sort products by Sale price and stock status
- Querying terms with calculations based on term meta data, sql vs. get_terms
- meta_query check multiple date formats
- WordPress meta query not working
- Get meta_value from GDRating
- WordPress meta query with meta serialized data array value
- Reading Content in an Array as it relates to a meta_query
- How to output meta_key in wp_postmeta?
- Meta query array – same order as specified order in value
- How to order product for key exists?
- Meta query terribly slow
- meta_query sorting by 2 keys
- How to handle optional end date in compare clause in meta_query
- Best practice – Meta Query vs. post_clauses for “left join” ordering
- Different page parameters inside query
- Is there a way to do multiple ordering on a multiple meta_query?
- LIKE %…% Meta Query
- Order by custom field date with ASC order
- Documentation for post meta
- Ordering posts by anniversary using only day and month
- Sort custom post types by last name in the backend
- pre_get_posts filter using numeric meta_query comparison (from dates)
- How to use meta_query to check if a meta field has something set?
- pre_get_posts and search query for admin
- Using database meta_values to calculate new post order using pre_get_posts or a ‘request’ hook
- Display custom post types with custom date field value (before today) & order by custom date field
- How to make a WP REST API query with meta_query in WP4.7?
- pre_get_posts filter meta_query without conflicting existing meta_query
- Query posts only if meta_value is not empty
- Complex Orderby Parameters: How to query with multiple orderby parameters using meta_value_num?
- Display post in order of ACF checkbox?
- How to pass user meta_key and meta_value (values as array)
- Query Multiple values for same key
- 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
- Query multiple meta values
- orderby meta_value breaks taxonomy term archives
- AJAX pagination offset returns same post on adjacent pages
- How do you get Posts by multiple meta_keys and meta_values with the Rest API V2?
- Meta_query on same meta key, with diffrenct values
- Query custom field with date
- Meta query with regular expression does not work
- Searching in title or meta, with a tax query too!
- Exclude posts from main loop based on meta value
- Why does pre_get_posts() return “date” as the orderby parameter for every sortable column?
- Pre Get Posts / Multiple Meta Keys / Orderby Single Key
- meta_query with multiple values optimization
- Get a single post ID based on an exact match of 1 or more meta values
- ORDER BY custom field value out of where clause
- Extend meta query arguments
- get_posts( $args ) return empty data
- WP_Query of custom post type sorted by meta_key has unexpected results
- how to search all user meta data that have value like “vivek”
- Sort posts using multiple custom fields and menu_order in single query?
- I can not display meta value in extras.php and template-tags.php
- How do I echo all users’ display_name and their meta_value who have a certain meta_key?
- Order (by ASC) posts with meta_key so posts without values are last
- Tax query get first product with attribute value in pre_get_posts
- Sort by DESC works, ASC doesn’t?
- meta_query is overriding default search
- WP_Query multiple value not working
- get_user can’t read variable
- WP_User_Query Orderby Not Working
- Pre get posts sort by meta key returns no results if meta key does not exist
- Meta_Query with multi select values
- Get Posts from Custom Meta Query
- Meta query broken since 4.7.4 Update
- Best way to Order Post in Home without a plugin
- How to fetch WP_User_Query with multiple role arguments [duplicate]
- How to get meta value based on latest post id with group by term name
- Want to order by Meta Values (tweaking Post Order Widget)
- Order posts by custom column using pre_get_posts
- Order Wp Query by earliest of 3 dates meta query
- How to use orderby on meta_value when using Pods custom database table storage
- acf/save_post affecting WP_Query results