Your example is a bit hard to understand, as it seems to query for meta_values of X,Y,Z,AB,ID,IA
. I hope you can still make sense of the below posted code:
// query posts that have on of the custom values for the custom meta key 'my_key'
// and/or one of the custom meta values for the meta key 'your_key'
$posts = get_posts( array(
'post_type' => 'my_post_type'
,'meta_query' => array(
array(
'key' => 'my_key'
,'value' => array( 'AB', 'ID', 'IA' )
,'compare' => 'IN'
)
,array(
'key' => 'your_key'
,'value' => array( 'AB', 'ID', 'IA' )
,'compare' => 'IN'
)
) );
Other comparison values would be 'LIKE', 'NOT LIKE', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'
where the later twos are reserved for numeric comparison and need an extra meta key/value pair: 'type' => 'numeric'
.
Related Posts:
- Meta Query with AND & OR?
- Upcoming Event: How do I sort database by custom date field, but ignore past dates?
- Conditional custom field query
- Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months
- The best way to collision check in WP
- Complex WP_Query Using Post Date And Post Meta
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- Filter WP_Query for posts having a certain meta-value
- How to rename a custom field?
- How can I make wp-pagenavi work on a custom query built upon a form submission? [closed]
- How do I search an array stored in a custom-field using WP_Query?
- How do I order by multiple custom fields using wp_query?
- Trying to perform complex custom field query with order by set to field value
- Query meta field using between
- Order Posts by Closest Numeric Values
- 2 orderby in wp_query with 2 custom fields
- Can serialized arrays in DB be matched against serialized arrays with meta_query?
- How to get a meta value from all post
- Compare meta_query decimals not working right
- WP_Query multiple use of relation and/or
- Query Problem – Show posts within category ‘x’ that have a custom field between ‘y’ and ‘z’
- Comparing timestamps in meta query doesn’t work
- Display two post types ordered by two custom fields
- Using OR in WP_Query negates the “NOT EXISTS” compare
- Having trouble with custom date field for CPT query (WordPress)
- Using WP Query to search by multiple meta fields
- Difference between ‘LIKE’ and ‘IN’ in meta queries
- Plugin similar to Taxonomy Drill-Down for custom fields?
- Compare WP Custom Field date
- Sort by posts that have a featured image?
- WP_Query display next custom post from today’s date
- Order by value in serialized custom field
- $wp_query meta_key naming issue [closed]
- Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
- Meta_query and numeric comparison [closed]
- Conditional to modify query results
- Count how many posts have a custom field set
- Any way to include custom fields in WP_Query results?
- sort search results by custom fields using dropdown
- Multiple relationships in a query
- Loop to display random posts only if a custom field matches category
- WP Query Returning All Posts
- How do I use wp_query for WordPress search?
- Order query by meta_value with multiple custom fields
- Display only past events on that page using Visual Composer Grid Bulider
- Custom Field Create Bulk via SQL Query
- Create Pop-Up Box with Custom Field Content Inside the Loop
- Auto Populate Custom Field with Complex Value That Increase by One?
- query usermeta from custom field
- Is there any way to get all meta and standard columns for any WordPress object after searching based on meta key and value
- Order RSS content by an advanced custom field value
- Order by empty custom field
- Alter main archive, to show posts with meta as last
- Custom WP_Query for WordPress Search Results with meta_query
- Meta Query And/Or
- How to combine custom fields to make one order-able value
- Trying to reorder posts by custom field
- Limits, not all post are showen when querying for posts by view count
- Get post ids sorted by meta_key
- querying a custom field
- pre_get_posts : only get posts by wp_usermeta value
- meta_value and meta_key filtering returning no posts [closed]
- Select custom posts by meta_value and sort by a different meta value
- Adding custom field and querying from post table
- List custom queried terms in the edit-tags.php?taxonomy page
- Loop through incrementing custom fields
- WP_query multiple custom fields not working
- WP_Query () using taxonomy, custom post types
- Multiple Custom Field Query
- Best way to sort estates and query them (for rent? yes/no. contains office space? yes/no)?
- Get array of posts based on custom field values
- How to update custom field of a posts in a particular category
- Searching with Multiple (Parallel) Criteria on Custom Fields?
- How to query posts by month based on date custom field?
- How can I modify my meta_query to work with prices that are stored in the database that contain dollar signs and commas?
- Custom Field Date Problem
- Query multiple post types, but different order for each
- Compare ACF date field (if exists) and post date and order DESC
- Problem with revisions only returning four results
- WP Query from two Custom Post type fields as statement
- Dynamically populate query source in Elementor post widget
- WP_Query not ordering correctly
- Query against multiple locations within single custom post type post
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- searching by keywords in post’s metas or pagination links problem
- Query by meta value (add a dropdown of all values)
- select user with all meta field and field value. I am use Below Query for this ,So any of know another way to fast query instead of below query?
- WP Query multiple select form – meta_query help
- How to Order Posts by Custom Fields?
- query specific posts according their custom fields, using sql SELECT
- Meta_query not filtering posts
- WP_Query based on multiple metadata comparisons
- Get multiple posts with some custom fields efficient
- How to add a prefix to existing custom fields over MYSQL query?
- Display posts where date field matches current month?
- How to check if custom field exists in this widget query
- Only show content slideshow if “slideshow” custom field exists
- Display agents (custom post type) alphabetically, except one who always shows last
- Filter Custom post type by another Custom post type
- Query posts by Custom Meta (checkbox) & Genesis Grid Loop