I manually added a “featured” meta key to 2 different posts with values of 1474 and 2213 and then ran a basic WP_Query() like so:
$qv = [
'meta_query' =>[
[
'key' => 'featured',
'value' => [1474, 2213],
'compare' => 'IN',
]
]
];
$r = new WP_Query($qv);
It pulled up both posts. This was query it generated:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
WHERE 1=1
AND (
( wp_postmeta.meta_key = 'featured' AND wp_postmeta.meta_value IN ('1474','2213') )
)
AND wp_posts.post_type="post"
AND (wp_posts.post_status="publish" OR wp_posts.post_status="private")
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC
LIMIT 0, 12
var_dump() out your WP_Query() and see what sql query WP is running.
Related Posts:
- meta_query with meta values as serialize arrays
- Use REGEXP in WP_Query meta_query key
- How to query posts based on lat-lng coordinate as post meta?
- Set Alias for meta_query arguments in get_posts()
- How to Compare Two Meta Fields
- Add indexing to meta_value in wp_postmeta
- Is it possible to orderby multiple meta_keys when using meta_value_num?
- Custom WP_Query order by post_meta and (author) user_meta
- Getting attachments by meta value
- Using custom meta_query with relation not working as expected
- WP_Query meta_query where meta value ends in space
- Nested query inside Logical operator OR not working in meta_query
- What is an efficient way to query based on post_meta?
- WP_Query not working as expected for attachments and custom meta_query
- How do I create my own nested meta_query using posts_where / posts_join?
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- How to order a post type with meta_value_num and if meta_value_num does not exist then order by date
- Exclude post on loop by multiple meta key value
- Querying by taxonomy vs Querying by Custom fields Speed Comparison
- How to query ‘posts_per_page’ to display a different blog posts index template?
- Order By Multiple Meta Fields
- Advanced WP Query hogs the SQL server
- Order posts by meta value and Date
- Query sticky posts with thumbnails
- Order WP Query posts by custom order calculated from post meta values
- How to get user_id from wordpress database inside ajax function?
- Meta query with order by another custom field
- How to query for custom field within Gutenberg block from outside of that post? [closed]
- WP_Query with multiple meta fields filter?
- How to combine meta_query and post__in in WP_Query
- Get meta info related to current post
- How to orderby meta_value_num with dollar ($) sign
- Creating arguments from loop for WP_Query meta_query
- Order a query result by a numeric meta key even if it does not exist, but put the posts with meta key first
- Single meta_query query using OR instead of AND in request’s WHERE statement
- Meta Query Array Error 500
- How to do meta_query for attachments?
- SQL: What is wrong with the following query (generated by WordPress WP_Query, ordering prices)
- Why isn’t my `meta_query` array functioning properly?
- Overwrite YoastSEO meta-tags with another page’s [closed]
- How to orderby multiple meta fields if some fields are empty
- Fetch Record based on meta key dates
- meta_query BETWEEN, but the range is stored in the custom field
- Suggestions on making this query/code more performant
- Is it possible to set specific posts to show first in a query?
- Order by meta value (numeric value lower to higher)
- Large AND OR query timing out
- Order ascending is ignored in meta query?
- WP_Query with different postmeta filter for each categories
- Slow WP_Query with ‘OR’ on meta_query
- Make meta query treat meta_value as 1 or 0
- Is this meta query problematic?
- WP Query Meta Value – How To Identify Specific, Unique Values?
- Order by meta_key doesn’t work
- Appending to existing WP_Query’s meta_query if exists
- Multiple meta_key ordering with pre_get_posts
- Get meta_value of a specific meta_key from all posts belonging to a specific custom type
- Custom query filter by ACF date custom field
- Nested array issue in meta_query
- Error in meta_query not get result
- Meta query with compare by more than 2 fields
- How to get current page nearest parent id?
- meta_query with array as value with multiple arrays
- Why doesn’t my WP Meta Query return any results?
- WP_Query meta compare must include ALL array values
- meta_query returning excluded result
- meta_query weird behaviour, static int will work, but not user data
- Creating a query that get all posts but places meta items first
- get_posts query is taking about 40 seconds to execute
- wp query to use both author id and meta_query
- meta_query – check for multiple meta values in key which holds an array of values
- WP_Query for a taxonomy value OR a custom post type meta field
- Searching for a specific month in a metadata saved as Timestamp (Wp_Query)
- Meta query orderby meta_value_num sorting by role first
- WP_Query on custom key and value
- Get posts having meta value between two numbers
- How to set meta_query if get_post_meta returns nested array for that key? [duplicate]
- Sorting with meta_query and multiple, optional meta keys
- Query by meta value (add a dropdown of all values)
- meta_query is not allowing to show posts when querying multiple arguments in a WP_Query
- Speed up WP_query with meta comparing dates
- Meta Query if Values Don’t Exist
- How to show all the associated posts with specific date of data metabox?
- WP_Query returns empty if meta_query has more than 7 values
- Is it possible to search for a string in posts OR postmeta?
- WP_Query Posts by Metadata from Option Tree
- WordPress meta_query not working
- Using orderby with 2 meta keys
- Passing conditional arrays to WP_Query() [closed]
- Why is WP_Query’s meta_query not filtering results?
- meta_query in wp_query not working as expected
- Get all user with both meta_value
- Using ‘meta_query’ with the ‘pre_get_posts()’ hook disables searching for post titles
- WP query with multiple custom meta not respecting orderby
- Get posts using multiple values from ACF checkbox as meta query wordpress
- WP Query returning all posts when Meta_query is null
- Passing a variable containing a comma separated list of values in a meta-query
- Complicated `orderby` based on text in custom field
- meta_query post_date not returning results
- WP Query: orderby with one meta key, but multiple values