In this situation you will want to use the meta_query
parameter, an example:
$args = array(
'post_type' => 'page',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => $key,
'value' => array($min, $max),
'compare' => 'BETWEEN',
),
),
);
$query = new WP_Query( $args );
The possible values for for the ‘compare’ key are:
- “=”
- “!=”
- “>”
- “>=”
- “<“
- “<=”
- “LIKE”
- “NOT LIKE”
- “IN”
- “NOT IN”
- “BETWEEN”
- “NOT BETWEEN”
- “EXISTS” (only in WP >= 3.5)
- “NOT EXISTS” (only in WP >= 3.5)
- “REGEXP” (only in WP >= 3.7)
- “NOT REGEXP” (only in WP >= 3.7)
- “RLIKE” (only in WP >= 3.7)
Default value is “=”.
Useful reading:
Related Posts:
- When should you use WP_Query vs query_posts() vs get_posts()?
- Get post ids from WP_Query?
- Some doubts about how the main query and the custom query works in this custom theme?
- Wp get all the sub pages of the parent using wp query
- How to query for most viewed posts and show top 5
- Using OR conditions in meta_query for query_posts argument
- Order posts by ID in the given order
- Get posts by menu ID
- WordPress Custom Query to show posts from last x years
- Get posts by meta data OR title
- Perform query with meta_value date
- Using is_main_query to select custom post type on certain page
- WP_Query ordered by custom field that is a date string?
- Meta Query with date and time on the same Day before given time
- get_the_title($postID) OR get_the_title()?
- Display Posts by modifying the where clause only for my query
- How do I create my own nested meta_query using posts_where / posts_join?
- Best practice for multiple queries on page
- How to Get All Posts but the Private ones?
- How to query ‘posts_per_page’ to display a different blog posts index template?
- How to find out what “Blog pages show at most” is set to [duplicate]
- Retrieve or Query Pages by ID
- How do you query wordpress posts using a math formula between multiple meta field values?
- How add a custom posttype name using ACF field to a query post array
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- Multiple instances of Featured Image Query
- How can I pick a single post from the latest 3?
- 2 loops on page – one with orderby rand second orderby date
- How do you Query posts with nothing in common?
- Custom category search box for WordPress
- Order a query result by a numeric meta key even if it does not exist, but put the posts with meta key first
- Query with custom taxonomy not working
- Query posts by specific word on title
- WP Pagination on Posts Search Results Page resulting from AJAX WP Query
- Store sticky post’s ids in a transient
- Five posts from a category in footer
- How to build a WP_Query using mulitple tags and using AND or OR operator between them
- Multiple loops without repeating content
- How can I create ‘future’ and ‘past’ parameter for restAPI by filtering the CPT custom date field by greater than / less than current datetime?
- How to display multiple custom fields with the same meta_key in an ascending order?
- new WP_Query(), have_posts() return false in user_register hook
- Bypass “supress_filters” in WP Query
- Some doubts about how the main query and the custom query works in this custom theme?
- How to display an other custom post type in a different custom post type’s archive?
- Display custom tags on pages that have a specific page parent
- How to exclude post formats from wordpress recent posts in a tabs widget [closed]
- How to increase load time of an archive/search page (WP_Query)
- Query all posts if multiple meta key don’t exist
- How to query for all posts that have a particular meta key?
- Exclude All Posts Which Do Not Have A Tag Assigned
- How can I override one post and make it display content for another post?
- Include current post into loop
- Get all posts which was posted on X Days WordPress
- Easy way to write complex queries in wordpress
- get_posts output always same post
- Conditional operator OR not working with custom fields
- complex get_posts() query to select child pages
- Get posts that do not have the same tags as current
- Should I reset $wp_query?
- Posts Query | Query to only show sub categories
- Posts query according to meta box date
- How to use ‘WP_Query’ or ‘query_posts’ to display content in a descending order
- Get next/prev image/attachment in time with date query
- Max Posts and Memory Limit
- Why doesn’t my WP Meta Query return any results?
- Determine if ID is page or post and query the ID
- How to query for a page, get data, then query for child pages of that page
- Magazine style frontpage with multiple categories/loops and no duplicate posts
- Optimising WP_Query with ACF Fields
- Query post and sort by custom value calculated with custom field on cpt
- Filter products on category AND tag
- Query post ordered by meta value that show first post that contained a tag
- query hook parse_tax_query function takes no effect
- ElasticPress is (aparently) messing with my search filters
- pre_user_query vs pre_get_posts
- How do I stop the same post showing multiple times in a archive?
- Order by meta date with a thousanth of a second defaults to post order
- Problem with my loops
- I need query_posts() to order results first by a meta value and then by post ID
- My entry results are not consistently alphabetized
- Orderby query does not work for custom fields even with meta query
- How to order posts, that have already been filtered by custom taxonomy, by their category names?
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- Calling body_class and wp_nav_menu for a different post
- query_posts() doesn’t seem to be called in my page
- Modify query to exclude certain ids and certain parents and its corresponding children
- Fetching $_POST from Page Template into functions.php
- How to order by datediff in WP loop?
- how to exclude store in clipper theme wordpress code php
- Display post list within category list sorted by name [duplicate]
- Optimising specific Query with ACF meta objects
- When should you use WP_Query vs query_posts() vs get_posts()?
- query_posts with sorting on a custom datestamp
- How to query post ids liked by the Author
- Query Posts by date range with fixed beginning and end
- get contents and permalink from a specified page
- Having trouble using this post category query on multiple pages?
- Exclude categories and subcategories in QueryLoop
- Incorrect posts displayed on category page
- Show number of posts AND number on current page (cannot make it work)