Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

WP_Query meta compare must include ALL array values

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:

  1. Query against multiple locations within single custom post type post
  2. order by numeric value for meta value
  3. Use REGEXP in WP_Query meta_query key
  4. Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
  5. What is the most efficient way of querying posts based on visits and date for current day?
  6. Custom WP_Query order by post_meta and (author) user_meta
  7. Query WooCommerce orders where meta data does not exist
  8. Getting attachments by meta value
  9. Query Custom Meta Value with Increment
  10. Perform query with meta_value date
  11. Finding all results from database within 500 miles of the given latitude and longitude [closed]
  12. What is an efficient way to query based on post_meta?
  13. WP_Query not working as expected for attachments and custom meta_query
  14. How can I create a WP_Query that returns posts where one meta_value
  15. WordPress altering my custom query, How to fix it?
  16. WP Meta Query for some meta (array) values
  17. How to get sum of meta_values of a meta_key in wp_query according to conditions
  18. Order posts by meta value and Date
  19. Meta Query for specific months
  20. Get meta info related to current post
  21. How to orderby meta_value_num with dollar ($) sign
  22. Pull post meta with post_query?
  23. How to make Meta Query case sensitive?
  24. Performance when getting post meta for post retrieved by meta value
  25. Get attachment by meta_key value
  26. Optional Meta Query
  27. Overwrite YoastSEO meta-tags with another page’s [closed]
  28. How to orderby multiple meta fields if some fields are empty
  29. Fetch Record based on meta key dates
  30. how to make members list directory through wordpress post custom meta key.
  31. Large AND OR query timing out
  32. Meta Query relation “AND” then set array accordingly
  33. Filter posts by comparing custom meta value against postdate
  34. WordPress query posts with multiple post_meta data
  35. How to set up hierarchical relationships without using plugins / meta query
  36. Is it possible to retrieve posts depending on meta_key LIKE condition? [duplicate]
  37. Nested array issue in meta_query
  38. Why doesn’t my WP Meta Query return any results?
  39. Query posts by searching for a string in a meta field
  40. meta_query where the meta value is not the post title
  41. Query multiple post types, but different order for each
  42. How do i create a custom post query when the meta value is an array?
  43. wp query to use both author id and meta_query
  44. Woocommerce Get Orders By Meta Value
  45. Meta query ignores multiple values of the key
  46. Trouble with serialized metadata
  47. How to do WP_User_Query for Nested Array value Inside Nested Array field
  48. show most viewed post
  49. Meta query orderby meta_value_num sorting by role first
  50. Why can my filter query SOME metadata but not other metadata?
  51. Strange results from WP_Query
  52. How to set meta_query if get_post_meta returns nested array for that key? [duplicate]
  53. I need query_posts() to order results first by a meta value and then by post ID
  54. WP Query. Ordering posts by another post types meta
  55. Slow wp_posts and wp_postmeta query using Advance Custom Fields
  56. Query by meta value (add a dropdown of all values)
  57. Meta query doesn’t remove placeholder escape before query
  58. What is the best way to reset a search on a meta_key / meta_value?
  59. Saving custom fields for WP_Query to retrieve
  60. How can I modify standard search query to include also ACF custom fields values?
  61. How to show all the associated posts with specific date of data metabox?
  62. WP Meta Query at depth 2
  63. WP_Query with child element
  64. Filter posts/pages by user_role array
  65. WP_Query Posts by Metadata from Option Tree
  66. How to get several fields from wp_query?
  67. Return a single custom post from multiple meta queries
  68. How to query post ids liked by the Author
  69. query by meta value then date and not empty meta value
  70. Query posts by meta value and sort by another meta key
  71. WP_Query by meta key not returning any posts
  72. Use meta query only 3 or more results?
  73. Use value from meta key array for use in WP_Query
  74. How to get posts that have certain meta key value and order based on another meta key’s value
  75. How to use meta_query to retrieve posts from multiple custom post type
  76. When should you use WP_Query vs query_posts() vs get_posts()?
  77. Meta_query compare operator explanation
  78. meta_query with meta values as serialize arrays
  79. How to only display posts whose meta_value field is not empty?
  80. Nested meta_query with multiple relation keys
  81. Can wp_query return posts meta in a single request?
  82. meta_query ‘compare’ => ‘IN’ not working
  83. Wp get all the sub pages of the parent using wp query
  84. How do I query for posts by partial meta key?
  85. Return only Count from a wp_query request?
  86. WP Query Args – Title or Meta Value
  87. How to query for most viewed posts and show top 5
  88. Meta query with string starting like pattern
  89. compare meta_query in get_posts arguments
  90. WordPress retrieving meta data for all custom post types in list view
  91. How to query posts based on lat-lng coordinate as post meta?
  92. WP_Query vs get_posts
  93. how to show posts that are missing a meta_value
  94. Order by optional meta key?
  95. Set Alias for meta_query arguments in get_posts()
  96. Sorting: custom query with orderby meta_value_num THEN by title
  97. meta_query: using BETWEEN with floats and/or casting to DECIMAL
  98. WP_Comment_Query pagination, delving into the unknown
  99. Usage of the new “posts_clauses” filter in WordPress 3.1?
  100. Display products from specific category in shop page
Categories wp-query Tags meta-query, post-meta, query, wp-query
Will adding & modifying default WordPress table index break future WordPress update
Adding a Tag Parameter / Filter to My Shortcode

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress