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

How do I have WP_Query match posts based on search parameter OR meta fields? (rather than search parameters AND meta fields)?

I had the same desire. A quick and dirty answer is to use the get_meta_sql to replace the leading 'AND' with an 'OR'.

(See also the answer here: https://stackoverflow.com/questions/43734845/how-to-give-or-relation-in-tax-query-and-meta-query-wordpress ( A related, but not duplicate, question.) )

Related Posts:

  1. Using meta query (‘meta_query’) with a search query (‘s’)
  2. Add custom fields to search
  3. Is there a way to do multiple ordering on a multiple meta_query?
  4. WordPress Search Custom Meta Field Only
  5. Ordering posts by anniversary using only day and month
  6. Displaying posts with only upcoming dates according their custom field date value
  7. Which is best in the following scenario : post_meta vs custom table vs parent/child posts
  8. How do I use wp_query for WordPress search?
  9. How make a custom search on backend in WordPress without plugin?
  10. filtering custom post types via meta data drop down
  11. How to add a new meta key and assign timestamp to posts
  12. Custom WP_Query for WordPress Search Results with meta_query
  13. filter custom field values $min $max
  14. How can you include custom post meta in search without calling each key?
  15. Ordering posts by custom field named “date” in backend
  16. Unique meta_key with array value vs repeated meta_key with single values
  17. Avoiding ACF get_field and returning to core WordPress function
  18. change order of images attached to post
  19. Need to search a custom field (ingredients, one long string per post), but want it to allow phrases/non-exact matches
  20. How to improve my non-unique metadata MySQL entries?
  21. searching by keywords in post’s metas or pagination links problem
  22. Search one custom field?
  23. Create custom query for search?
  24. Query postmeta values, and return multiple post_titles for common meta value
  25. WP Query Args – search by meta_key or title
  26. Search for meta_query does not return any result if combined with title
  27. SQL query based on two different custom field values
  28. Can I exclude a post by meta key using pre_get_posts function?
  29. Advanced search form with filters for custom taxonomies and custom fields
  30. Custom post meta field effect on the performance on the post
  31. How to get custom post meta using REST API
  32. Difference between meta keys with _ and without _ [duplicate]
  33. Orderby meta_value only returns posts that have existing meta_key
  34. What is the index [0] for on post meta fields?
  35. What is “meta_input” parameter in wp_insert_post() used for?
  36. How to enable revisions for post meta data?
  37. The “_encloseme” Meta-Key Conundrum
  38. ORDER BY custom field value
  39. Best way to programmatically remove a category/term from a post
  40. Using get_post_meta with new_to_publish
  41. Can I query custom meta data through WP_Query
  42. Including custom fields in search?
  43. Admin Area Custom Type Search By Meta Fields Without Title & Content
  44. SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
  45. Matching Serialized Arrays with meta_query
  46. Custom field metabox not showing in back-end
  47. How do I Paginate Search Results for Custom Post Types?
  48. Meta Query with AND & OR?
  49. So much data in postmeta
  50. Custom search: by post data and post metadata?
  51. Can I count the number of users matching a value in a multiple value key?
  52. Need small coding with Custom Fields Search
  53. Getting attachments by meta value
  54. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  55. How to hide meta box values from custom fields list?
  56. Auto sort the wp-admin post list by a meta key
  57. get_post_meta() unserialize issue – returns boolean(false)
  58. What is the advantage of the wp_options design pattern?
  59. Search ONLY by meta key / meta values
  60. Storing meta fields multiple times OR once with multi dimensional array?
  61. Allow user to create instances of custom field
  62. display specific custom fields
  63. How Can I save multiple records in same meta key?
  64. Is there a hook / action that is triggered when adding or removing a post thumbnail?
  65. Filter results with custom field values and dropdown
  66. Meta keywords and descriptions plugin for manually editing meta for each page/post
  67. Add custom field (value) to search result (without plugin)
  68. passing argument to get_template_part() or a better way to code
  69. Is it possible to store arrays in a custom field?
  70. Get updated meta data after save_post hook
  71. Multiple meta values for same meta_key adding on “Preview Changes” hit but not on saving or updating post
  72. Save HTML formatted data to post meta using add_post_meta()
  73. Trying to perform complex custom field query with order by set to field value
  74. Search everything (posts, pages, tags, cpt, meta)
  75. importing data from non-wordpress mysql db
  76. searching in custom meta field
  77. Create meta boxes that don’t show in custom fields
  78. Transients vs CRON +Custom Fields: Caching Data Per Post
  79. Unable to save datetime custom meta field using update_post_meta() function
  80. Up/Down voting system for WordPress
  81. post meta data clearing on autosave
  82. Create custom field on post draft or publish?
  83. Display info from custom fields in all images’ HTML
  84. Compare meta_query decimals not working right
  85. WordPress altering my custom query, How to fix it?
  86. Calling Specific Pages with wp query Part II
  87. Loop through two different sets of custom fields
  88. Exclude custom post type from search by custom field value?
  89. get_post_meta fields don’t show up on posts page
  90. Update meta values with AJAX
  91. How to break meta values into different items and avoid duplicates?
  92. copy attachments to another post type and change attachment url
  93. Cannot edit post meta fields with rest API
  94. ajax delete value from custom field array
  95. Save attachment custom fields on front end
  96. Slow meta query with multi meta keys
  97. How to use pagination with get_post_meta
  98. Copying Custom Meta Values from existing post to a duplicate post
  99. Using OR in WP_Query negates the “NOT EXISTS” compare
  100. Add a post meta key and value only if it does not exist on the post
Categories custom-field Tags custom-field, meta-query, post-meta, search
Enable WordPress to share cookies between domain.com and sub.domain.com
How to Upload CSV Data into Custom Post Type Data with Metabox programmatically

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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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