You can have multiple meta_query
arguments with the same key and that will produce the results you’re seeking. Here’s an example:
$meta_query = array_map( create_function( '$a', 'return array("key" => "row_amenities", "value" => $a);' ), $amenities );
$the_query = new WP_Query(array(
'post_type' => 'listing',
'posts_per_page' => -1,
'post_status' => 'publish',
'category_name' => 'private_rental',
'orderby' => 'rand',
'meta_query' => $meta_query
));
If $amenities
will have a lot of values (> 10), you should probably take a different approach, because it will join the postmeta table for each meta_query.
Related Posts:
- Query against multiple locations within single custom post type post
- order by numeric value for meta value
- Use REGEXP in WP_Query meta_query key
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- What is the most efficient way of querying posts based on visits and date for current day?
- Custom WP_Query order by post_meta and (author) user_meta
- Query WooCommerce orders where meta data does not exist
- Getting attachments by meta value
- Query Custom Meta Value with Increment
- Perform query with meta_value date
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- What is an efficient way to query based on post_meta?
- WP_Query not working as expected for attachments and custom meta_query
- How can I create a WP_Query that returns posts where one meta_value
- WordPress altering my custom query, How to fix it?
- WP Meta Query for some meta (array) values
- How to get sum of meta_values of a meta_key in wp_query according to conditions
- Order posts by meta value and Date
- Meta Query for specific months
- Get meta info related to current post
- How to orderby meta_value_num with dollar ($) sign
- Pull post meta with post_query?
- How to make Meta Query case sensitive?
- Performance when getting post meta for post retrieved by meta value
- Get attachment by meta_key value
- Optional Meta Query
- 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
- how to make members list directory through wordpress post custom meta key.
- Large AND OR query timing out
- Meta Query relation “AND” then set array accordingly
- Filter posts by comparing custom meta value against postdate
- WordPress query posts with multiple post_meta data
- How to set up hierarchical relationships without using plugins / meta query
- Is it possible to retrieve posts depending on meta_key LIKE condition? [duplicate]
- Nested array issue in meta_query
- Why doesn’t my WP Meta Query return any results?
- Query posts by searching for a string in a meta field
- meta_query where the meta value is not the post title
- Query multiple post types, but different order for each
- How do i create a custom post query when the meta value is an array?
- wp query to use both author id and meta_query
- Woocommerce Get Orders By Meta Value
- Meta query ignores multiple values of the key
- Trouble with serialized metadata
- How to do WP_User_Query for Nested Array value Inside Nested Array field
- show most viewed post
- Meta query orderby meta_value_num sorting by role first
- Why can my filter query SOME metadata but not other metadata?
- Strange results from WP_Query
- How to set meta_query if get_post_meta returns nested array for that key? [duplicate]
- I need query_posts() to order results first by a meta value and then by post ID
- WP Query. Ordering posts by another post types meta
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- Query by meta value (add a dropdown of all values)
- Meta query doesn’t remove placeholder escape before query
- What is the best way to reset a search on a meta_key / meta_value?
- Saving custom fields for WP_Query to retrieve
- How can I modify standard search query to include also ACF custom fields values?
- How to show all the associated posts with specific date of data metabox?
- WP Meta Query at depth 2
- WP_Query with child element
- Filter posts/pages by user_role array
- WP_Query Posts by Metadata from Option Tree
- How to get several fields from wp_query?
- Return a single custom post from multiple meta queries
- How to query post ids liked by the Author
- query by meta value then date and not empty meta value
- Query posts by meta value and sort by another meta key
- WP_Query by meta key not returning any posts
- Use meta query only 3 or more results?
- Use value from meta key array for use in WP_Query
- How to get posts that have certain meta key value and order based on another meta key’s value
- meta_query ‘compare’ => ‘IN’ not working
- Sorting: custom query with orderby meta_value_num THEN by title
- How to grab metabox value in wp_query meta_query key
- Add and in the header while looping over custom query in page template
- How to count data records in wordpress which have same meta_value in wp_postmeta table?
- Minimize database queries to user tables?
- unable to retrive parent page information
- WP Query related posts by tags
- Query only the posts with a post format of “audio”
- Order by meta_key doesn’t work
- Multiple meta_key ordering with pre_get_posts
- Prioritising and Ordering Posts By Category Name Using A Custom Loop
- Filter products on category AND tag
- meta_query – check for multiple meta values in key which holds an array of values
- Searching for a specific month in a metadata saved as Timestamp (Wp_Query)
- Doing $wpdb->get_results returns NULL, doing the same query in my DB returns correct value
- How to get meta key list efficiently?
- Get posts having meta value between two numbers
- Query posts in current category but not attachment format
- WordPress meta_query not working
- Using orderby with 2 meta keys
- wp_query – Modify $query to include duplicate content
- Optimising specific Query with ACF meta objects
- How do I subquery with custom meta fields?
- Advanced Search – Is this possible?
- Extend search query to search meta keys values based on search string