From the codex http://codex.wordpress.org/Class_Reference/WP_Query:
$args = array(
'post_type' => 'my_custom_post_type',
'meta_key' => 'age',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'age',
'value' => array(3, 4),
'compare' => 'IN',
)
)
);
$query = new WP_Query($args);
Look at the meta_query section. you can define the key and then all the possible values in a array. You can also define the type of comparison (eg. great than, equal, IN).
Related Posts:
- meta_query with meta values as serialize arrays
- How to only display posts whose meta_value field is not empty?
- Order by multiple meta key and meta value [closed]
- WP_Query with checkbox meta_query
- Is it possible to orderby multiple meta_keys when using meta_value_num?
- WP_Query with meta_value LIKE ‘something%’
- How to grab metabox value in wp_query meta_query key
- Sorting meta_value as integer doesn’t work
- Add a default meta_value to new posts
- Ordering by meta_value AND date NOT WORKING with wp_query
- How to use Meta Value Compare in WP_Query For Max and Min numbers
- Custom WP Query from meta_value stored as serialised array
- meta_query works locally but not on live server
- Ordering Posts Type A by Custom Fields of related Post Type B
- Meta box dropdown of custom posts
- Custom query for sidebar isn’t returning results
- Need wp_query to return all children and grandchildren
- new WP_Query to get max price meta value not working
- Query multiple meta values
- Why isn’t my `meta_query` array functioning properly?
- How to orderby multiple meta fields if some fields are empty
- Custom Metabox data slow query on Admin init
- Meta_query on same meta key, with diffrenct values
- How to extract specific post
- Meta Query relation “AND” then set array accordingly
- New WP_Query loop in admin causes problems
- Does meta_value (array) work with ‘orderby’?
- WP Query Meta Value – How To Identify Specific, Unique Values?
- Posts query according to meta box date
- create metabox to activate slider
- query post by author gender
- Show posts of an advanced search form
- How do I add an item to the WP admin menu?
- Meta query with compare by more than 2 fields
- Help with if statement inside while loop
- wp list pages using meta box value
- Meta Box WP_Query array for showing items with a certain relationship
- Order (by ASC) posts with meta_key so posts without values are last
- Add metabox if there is at least one post available
- meta_query with meta values as serialize arrays
- Save queried result into database
- WP_Query multiple value not working
- update_post_meta() not updating
- Query by meta value (add a dropdown of all values)
- Gather same custom field values in one value in a select tag with wp_query
- Wp Query sort order
- Saving custom fields for WP_Query to retrieve
- How to show all the associated posts with specific date of data metabox?
- Order posts by more than one variable (meta_key and publish date AND time)
- display post multiple times based on array of dates
- how to query for meta_value have array
- Sorting Posts with meta value not working
- Cannot order by in WP_Query
- Order by meta values
- query_posts, oderby meta_value & print “future” posts
- Get posts by meta value except one post [closed]
- Show posts without term
- Hook/action after WP_Query gets posts to query custom tables for post-related meta
- WP_Query to show post from a category OR custom field
- Add the “active” class only to the first loop item in a WordPress query [closed]
- Display Posts by modifying the where clause only for my query
- Pagination causes error 404 when used with front-page.php
- Using AJAX to return search form results
- How to get a category in a list item class
- Finding post content that begins with a specific character
- Use ‘parse_query’ filter to show posts that from multiple criteria
- Get posts for last working week in WP_Query
- how to link to detail page(single.php?) in a wp_loop
- Meta Query Array Error 500
- Get pagination working for custom loops within page templates
- Complex WP SQL Query
- how would i change post->ID to work correctly when querying pages?
- WP User Query with Custom Fields and Search Results
- Event with multiple dates, display events chronologically
- WP_Query order by not working properly due to category I believe
- WP_Query to get post on frontpage
- When listing child pages run out of memory
- Function to retrieve IDs of posts, cache results, and improve wp_query
- Search.php – return number of results but cannot loop through
- Show X taxonomies of the latest published posts
- Custom wp_query inside a conditional stament inside a template part doesn’t work: why?
- Query to show post current day
- Check the stored / cached WP_Query with transients on post change
- New template file does not load category-specific post
- WPQuery loop not giving expected output
- WordPress tax_query ignoring relation OR
- pagination functions are not working
- Wrap group of wp query posts to parent div by date/year
- Continue loop after $queryObject
- Declare inline background image in functions.php
- When should you use WP_Query vs query_posts() vs get_posts()?
- Can’t get pagination to work with this WP_Query loop
- Passing additional variables to a query
- I want to capture the last day’s (today) posts in a category in the numbered order in acf
- How do I have multiple metaqueries inside one wordpress query
- Query All Posts: Either Display Most Recent or One with Particular ACF Value Chosen
- Why am I getting no results of a query placed after another query?
- Can I use WP_Query to find a post with a particular menu_order?
- Display only posts with thumbnails
- How to efficiently find “duplicate” posts, where the titles are different, using metadata to match posts?