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
- Meta_query compare operator explanation
- meta_query ‘compare’ => ‘IN’ not working
- Sorting: custom query with orderby meta_value_num THEN by title
- WP_Query with checkbox meta_query
- ACF Relationship Field Search Filtering [closed]
- Get posts by menu ID
- Meta Query with date and time on the same Day before given time
- How to grab metabox value in wp_query meta_query key
- Is “orderby” in WP Meta Query conflicting with Meta Query?
- Stop all SQL_CALC_FOUND_ROWS wordpress queries
- How can I create a WP_Query that returns posts where one meta_value
- WP_Query hit max joins… How else can I build a search function that uses custom fields?
- Sort users by meta_value_num
- meta_query with array as value
- How to count data records in wordpress which have same meta_value in wp_postmeta table?
- Using WP Query to search within ALL keys in meta query
- How to speed up wp_query, took more 5s to run against 100k posts
- How to sort posts in admin by titles with dd.mm.yyyy format?
- Including only current user’s posts in search
- Custom query based on meta key – Reduce three states to two in results?
- Remove category from query (show all posts in archive.php) pre_get_posts()
- Query multiple meta values
- How to display multiple custom fields with the same meta_key in an ascending order?
- Meta_query with multiple keys and multiple values
- WP_Query ignoring tax_query when is_singular
- Tax query AND/OR meta query [duplicate]
- New WP_Query calls Pre_get_posts filter twice
- how update data through ajax and jquery
- how to get Nearby zipcode
- Is this meta query problematic?
- Appending to existing WP_Query’s meta_query if exists
- Get meta_value of a specific meta_key from all posts belonging to a specific custom type
- Custom query filter by ACF date custom field
- Is it possible to retrieve posts depending on meta_key LIKE condition? [duplicate]
- Nested array issue in meta_query
- Child pages not affected by orderby
- Error in meta_query not get result
- Comparing 2 Decimal Numbers from custom fields and displaying posts
- How to get current page nearest parent id?
- meta_query with array as value with multiple arrays
- Why doesn’t my WP Meta Query return any results?
- Search filter between promo and exact price
- meta_query – check for multiple meta values in key which holds an array of values
- SQL to join u3g_users & u3g_meta_value with repeating data
- WordPress Meta Query Null Values Order
- show most viewed post
- Searching for a specific month in a metadata saved as Timestamp (Wp_Query)
- WP_Query on custom key and value
- Get posts having meta value between two numbers
- How to set meta_query if get_post_meta returns nested array for that key? [duplicate]
- Case insensitive ORDERBY in wpquery
- Sorting with meta_query and multiple, optional meta keys
- Pre_get_posts only show posts by administrator roles
- How order by works?
- meta_query with relation = AND not working as expected when combining EQUALS with NOT EQUALS
- WP Query for Multiple Post Types
- Query by meta value (add a dropdown of all values)
- make query more simplest and in one query
- WP_Query returns empty if meta_query has more than 7 values
- Compare meta key separation
- WordPress meta_query not working
- Using orderby with 2 meta keys
- wp_query – Modify $query to include duplicate content
- Filter WP_Query output before it is accessed (pre_get_posts)?
- Passing conditional arrays to WP_Query() [closed]
- meta_query dates from an array
- WordPress Query Default Order if Meta Values Same?
- Avoiding page loop
- Wp query by 2 meta field – check if they exists / have value
- Get all user with both meta_value
- How to get all post_id and meta_value using meta_key in wp_postmeta table
- WP Query – Show custom posts only if user contain some user meta
- How do I subquery with custom meta fields?
- Bulk delete comments, foreach loop
- Showing Counts on Comment List with Custom Query