Add this to your plugin or functions.php file of your theme. The example below will include ‘your_key’ in search. You can include all your keys by repeating the array.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | function me_search_query( $query ) { if ( $query->is_search ) { $meta_query_args = array( array( 'key' => 'your_key', 'value' => $query->query_vars['s'] = '', 'compare' => 'LIKE', ), ); $query->set('meta_query', $meta_query_args); }; } add_filter( 'pre_get_posts', 'me_search_query'); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.