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:
- Posts with at least 3 tags of a list of tags
- Get post count of current loop when using multiple queries on one page
- Display products from specific category in shop page
- How to uniquely identify queries?
- Use WP_Query with a custom SQL query
- Pagination not working for Custom search form & custom result template
- Using next/previous_posts_link with customised search
- How to display most recent posts that haven’t already been displayed with WP_Query?
- What is the difference between these two custom queries?
- Display featured products through custom loop in WooCommerce 3 [closed]
- Array Chunks and Inserting Varying HTML in WP_Query
- Filter user list that meta_value is empty
- Query wp_usermeta alongside wp_users
- Understanding the use of wp_reset_query();
- How to output different posts per page?
- Multiple WP_Query loops with Pagination Not Working
- WordPress posts per page WP_Query
- WooCommerce Only OnSale Products Loop Snippet [closed]
- WP_Query times out
- ACF – Get lowest & highest value from field
- What format does the meta_query TIME type require?
- wp_query add arguments using array_push if variable met
- tax_query: Order by slug?
- WP_Query date_query – Use unix timestamp?
- WP_Query filter and order by meta ordering by wrong joined table
- WP_Query last five posts, simply ordered by meta_value
- How to display specific posts with WP_Query?
- WP_Query “OR”: Find posts by ID, Name or Post Title?
- What is the random string I am seeing when I use get_query_var?
- Querying on multiple taxonomies pulled from $_GET checkbox array not working?
- WP_Query condition affects posts_per_page count
- WP_Query order result by date AND meta_value
- Display tags with random thumbnail from selection of posts with that tag
- Is there a way to work with a specific the_field from an already queried post? [closed]
- slow WP_Query for non-admin user
- Changing sort order for presentation by Jetpack infinite scroll
- How to search for posts given post_content AND post_excerpt using WP_Query?
- Add capabilities via plugin for another plugin
- Filter and Order by Multiple Custom Meta Values
- Meta Query relation “AND” then set array accordingly
- Does wp track views for posts?
- WP_query exclude posts of a format
- post_type argument not working correctly with WP_Query
- Custom query with meta_key not working fine
- Can I simplify in function column_default use of queries
- How to provide meta_key array to wp_query?
- how to get wordpress user id when user register
- Highlight post in sidebar on single page
- Specify strict ‘order by’ in WordPress query
- WP query is calling get_userdata and throws error [closed]
- How to set up hierarchical relationships without using plugins / meta query
- Single field to search for matches on post ID or meta values
- 2 column recent post query not respecting float right [closed]
- Meta query compare for ID’s greater than specific ID
- WP_Query->request has a limit
- Slider won’t work with custom query
- wordpress udpate query not equal to
- How to generate feed for custom template
- WP_Query with one category in args shows other categories
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- Why does apply_filters behave different inside and outside a loop?
- Excluded category from loop
- Add content depending on page loaded
- Having a variable based on $post_count increase when i move to the next page of results
- Post order by custom fields
- WP Query and multiple pages
- Elementor posts custom query based on tag [closed]
- How can I do a orderby by the number of items? So basically list by starting with the array with the largest number of post
- How do you do a meta query on an encrypted field?
- meta_query with meta values as serialize arrays
- Custom Woocommerce Product Query
- Multiple WP_Query args combinations according to post type
- in_the_loop() issue with custom query
- Pagination inside the blog page not working
- How to restrict add media library only to images of the same post family?
- Post Template Query with WP_Query?
- Wp Query sort order
- get_posts query caching?
- Adding additional taxonomies to wordpress taxonomy page
- why doesn’t this pre_get_posts code work?
- pre_get_posts with WP_Query to prevent posts from specific tags
- Best way to Order Post in Home without a plugin
- Retrieving category pages from subcategory returns empty sets
- How to get query results for the next page
- Loop through multiple custom fields with increasing number
- Different number of posts showing in development vs production server
- Get post closest to today
- Multiple loop for “featured” items returns wrong posts
- Get WP_Query query after execution?
- Pagination in custom query not working [duplicate]
- query_posts problem – need help
- $query_args for loop to only get posts from “current category”?
- 294 Queries on Mainpage of WordPress
- Pagination on custom post type not working
- How do I subquery with custom meta fields?
- Show number of posts AND number on current page (cannot make it work)
- Advanced Search – Is this possible?
- Same query args showing different results order when setting different number of posts
- WordPress DB query
- $wpdb->get_results() into foreach() returns always the word “Array” on top of the list . How to get rid of?