You’re better off running two queries, then merging the results.
$first = get_posts( [
'fields' => 'ids',
's' => $s,
// ...
] );
$second = get_posts( [
'fields' => 'ids',
'meta_query' => ...
] );
$ids = array_values( array_unique( array_merge( $first, $second ) ) );
$query_args = [
'post__in' => $ids,
// ...
];
If your posts and postmeta tables are large and you’re concerned with performance, then you should be looking to run your searches on a proper index like Sphinx, Elasticsearch, etc., or build your own indexed column inside MySQL on wp_posts.
Related Posts:
- Meta_query compare operator explanation
- Exclude post ID from wp_query
- Can I force WP_Query to return no results?
- Use the page slug in a WP_Query?
- Exclude a category if post is only in that category using wp_Query
- paginate_links() adds empty href to first page and previous link
- Using OR conditions in meta_query for query_posts argument
- Too slow when using both ‘tax_query’ and ‘meta_query’ both in WP_Query
- Use of caller_ get_ posts
- Tax_query terms ID’s using variable
- Get array of posts from the current archive page loop
- Get posts by menu ID
- count posts from custom taxonomy terms by year
- Custom query incorrectly returning everything [closed]
- Last post ordered by publish date using WP_Query on front page
- Pagination custom query
- WP_Query and name__in
- Query certain amount of posts from multiple dates
- Meta Query with date and time on the same Day before given time
- In loop: posts have thumbnail AND other variables
- How to grab metabox value in wp_query meta_query key
- Woocommerce query by price range and custom meta key
- Get posts with condition on comment meta value
- Order posts by tags count?
- Orderby = none not working [duplicate]
- Add inline HTML to posts published within last 24hrs
- Add and in the header while looping over custom query in page template
- Stop all SQL_CALC_FOUND_ROWS wordpress queries
- Move posts to top of WP_Query if in certain Taxonomy?
- WP_query ‘orderby=none’ Problem
- Querying Multiple Custom Taxonomy Terms
- Single page theme
- Pagination not working on static page
- How can I create a WP_Query that returns posts where one meta_value
- ‘paged’ in wp_query doesn’t work
- Sorting meta_value as integer doesn’t work
- Unable to combine “search value” and “tax_query” using WP_Query
- How to extend tag and category “Related Posts” query to custom post_type if the first 2 terms have no posts
- Get posts from the Main site to sub site – WordPress MultiSites Network
- Custom Field Query – Meta Value is Array
- WP_Query search for whole words
- WordPress pagination link always leads to home page
- Query posts with more than 20 comments
- Can certain (site-crashing) limitations on WP_Query in shortcode be overcome?
- Get array of current post term ID’s
- WP_Query for showing specific post by id
- Ordering by meta_value AND date NOT WORKING with wp_query
- WP_QUERY returns empty set when fired from a WP-CRON scheduled event
- Query by custom dates in UNIX Time
- Custom WP Query from meta_value stored as serialised array
- Interupting the loop with extra divs to display data, and how to get it to work responsively
- Including only current user’s posts in search
- Implementing an OR statement to wordpress wp_query
- Get List of all the Authors
- How to check if a post “does not have term” in conditional statement?
- WP_Query, tax_query and term_meta: How to?
- How can i simulate “taxonomy__in” in query?
- How do I reset this wp_list_categories query?
- Refine search results using WP_Query
- query_posts: how to show all ‘meta_value’ containing a specific word?
- How to pass many ids in post__in?
- How to show subcategories using loop?
- Minimize database queries to user tables?
- WP_Query returns more results than expected
- Query with a meta value inside a given range
- Pagination of a WP_Query Loop in a child-page page template
- Add condition of user capability in WP_query
- add_filter() depending on search term
- Get all products which have both product category
- How to make Meta Query case sensitive?
- Populate tax_query terms parameter with post term
- Orderby the sum of several numeric custom meta fields
- unable to retrive parent page information
- How do I run through a WordPress loop called from a filter function?
- Site not getting correct featured image from my query
- Using WP_Query within an mu-plugin
- How do I get the title of a category in a custom loop?
- Fastest way of counting posts of a custom post type in a specific taxonomy term?
- wp_query ‘s’, search filter with pagination is not working
- Use more than one query, but prevent duplicates – at scale!
- Is it a good idea to improve meta query performance by adding tax query?
- WP_Query: Group events by year, sorted DESC; then by date for each year group, sorted ASC
- How to display user order by role
- WP_Query | Tax_Query Relation | Unable to use ‘OR’ as it then allows all products, help me finish my query?
- WP Query related posts by tags
- How to add posts, manually, to a wp_query?
- hide custom post types with specific meta key ON admin backend
- Why is wp_query causing an uncaught error to is_user_logged_in() not defined?
- Modify wp-query and sort by post meta key
- wp_reset_postdata() does not work as expected
- Search Query for multiple categories using ‘OR’ but having certain categories be ‘AND’
- WP_query with OR relation between args[‘s’] and arg[‘meta_query’]
- Orderby listing issue
- Check if loop has any categories?
- WordPress query with items from more than one selfdefined taxonomy as `term` argument
- How to display an other custom post type in a different custom post type’s archive?
- Current post in AJAX call is always zero
- Multiple filter conditions for WP_Query
- Get all fields inlcuding “ACF” (Advanced Custom Fields) columns in wp_query
- Replacing raw database query to WP_Query