I believe the shortest and best approach is to (1) modify the query:
function search_faqs_metadata($query) {
if(!is_admin() && $query->is_main_query()) {
if($query->is_search) {
$query->set('meta_query', array(array(
'key' => '_faqs',
'value' => $query->query_vars['s'],
'compare' => 'LIKE'
)));
}
}
}
add_action('pre_get_posts', 'search_faqs_metadata');
and then (2) replace the AND
with OR
via the get_meta_sql
filter:
function change_meta_key_where_from_and_to_or($sql) {
if(is_search()) {
$sql['where'] = substr($sql['where'], 1, 3) == 'AND' ? substr_replace($sql['where'], 'OR', 1, 3) : $sql['where'];
}
return $sql;
}
add_filter('get_meta_sql', 'change_meta_key_where_from_and_to_or');
Related Posts:
- 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
- Slow SQL_CALC_FOUND_ROWS Query
- Order By Multiple Meta Fields
- pre_get_posts filter meta_query without conflicting existing meta_query
- Using WP_Query and WP_Meta_Query Outside of WordPress
- pre_get_posts order by not working
- Performance when getting post meta for post retrieved by meta value
- Using meta_query with multiple keys and compare values
- Mysql query and order meta value
- Help ordering Post loop by two meta values
- Order ascending is ignored in meta query?
- Meta Query doesn’t works as espected
- How I can change the condition or compare operator for WP_Query in pre_get_posts
- Multiple meta_key ordering with pre_get_posts
- Sorting search results with custom dropdown
- WP Query – grouping posts by same meta key, adding together values from another key
- Woocommerce Get Orders By Meta Value
- meta_query is overriding default search
- WordPress Query optimaization for slow query
- Pre get posts sort by meta key returns no results if meta key does not exist
- Order Posts By Custom Field That is an array of objects
- Slow query when selecting with large meta query or post__in
- Sort posts in dashboard using custom field; also include posts where field isn’t set
- Looking for a way to exclude frontpage and nav menu from query filter
- When to use WP_query(), query_posts() and pre_get_posts
- Meta_query compare operator explanation
- meta_query with meta values as serialize arrays
- Should I use Pre Get Posts or WP_Query
- Nested meta_query with multiple relation keys
- Using pre_get_posts with WP_Query
- meta_query ‘compare’ => ‘IN’ not working
- Return only Count from a wp_query request?
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- WP Query Args – Title or Meta Value
- Meta query with string starting like pattern
- compare meta_query in get_posts arguments
- How to query posts based on lat-lng coordinate as post meta?
- how to show posts that are missing a meta_value
- What is “main query”? [duplicate]
- Set Alias for meta_query arguments in get_posts()
- Sorting: custom query with orderby meta_value_num THEN by title
- Order by DESC, ASC in custom WP_Query
- How to prevent execution of default query, while preserving ability to use WP_Query in template?
- Display products from specific category in shop page
- Reduce or prevent calling of update_meta_cache
- How to add taxonomy filter on the query fly?
- How to Compare Two Meta Fields
- Does tax_query really beats meta_query in all situations?
- WP_Query with checkbox meta_query
- ACF Relationship Field Search Filtering [closed]
- How to uniquely identify queries?
- Add indexing to meta_value in wp_postmeta
- Is it possible to orderby multiple meta_keys when using meta_value_num?
- Order Search Results Page by meta_value If no Value Return Remaining Results
- 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 Multiple Post types each with own meta query
- pre_get_posts with get_posts
- How-to exclude terms from the main query the most performant way?
- Get posts by menu ID
- Changing Posts Per Page and offset with pre_get_posts
- Execute a large WP_Query with many “AND” Meta_Queries?
- Query all posts where meta value is empty
- WP_Query min and max values
- “pre_get_posts” firing on every query
- RSS feed with specific keyword
- ACF datepicker meta_query Compare Dates in m/d/Y g:i a – Not in Ymd Format
- WP_Query using meta_query with relation OR and orderby meta_value doesn’t work
- Using custom meta_query with relation not working as expected
- Perform query with meta_value date
- Using is_main_query to select custom post type on certain page
- querying with custom meta field with meta_query
- Order by two meta keys
- multiple meta key but get server load is very high
- Meta Query with date and time on the same Day before given time
- A WP_Query that will look for posts after 2 weeks ago OR with a certain meta value
- Multiple orderby parameters in pre_get_posts() action
- How to grab metabox value in wp_query meta_query key
- WP_Query meta_query where meta value ends in space
- Order by meta_value_num DESC and meta_value ASC on WP 4.0
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- Nested query inside Logical operator OR not working in meta_query
- SQL Statement generated by WP_Query not producing expected results
- Is “orderby” in WP Meta Query conflicting with Meta Query?
- Query by meta_key and order by meta_value_num return orderby date
- What is an efficient way to query based on post_meta?
- WP_Query not working as expected for attachments and custom meta_query
- SQL query equivalent to WP User Query
- datetime picker, timestamps and meta queries
- How do I create my own nested meta_query using posts_where / posts_join?
- What’s wrong with this WP query?
- Stop all SQL_CALC_FOUND_ROWS wordpress queries
- How to count post meta key values for all posts in database
- Sorting Posts by custom field
- How to pass custom parameter to WP_Query for filtering in pre_get_posts
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- How to order a post type with meta_value_num and if meta_value_num does not exist then order by date
- Query with pre_get_posts to get pagination