Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function bedrooms_guests_search_query( $query ) {
- if (! is_admin() && $query->is_main_query()) {
- $custom_fields = array(
- // put all the meta fields you want to search for here
- "function_camere","function_ospiti"
- );
- $searchterm = $query->query_vars['tipologia'];
- // we have to remove the "s" parameter from the query, because it will prevent the posts from being found
- $query->query_vars['s'] = "";
- if ($searchterm != "") {
- $meta_query = array('relation' => 'OR');
- foreach($custom_fields as $tipologia) {
- array_push($meta_query, array(
- 'key' => $tipologia,
- 'value' => $searchterm,
- 'compare' => 'LIKE'
- ));
- }
- if ( array_key_exists('funzione_camere', $_GET ) && $searchterm != "")
- if ( array_key_exists('funzione_ospiti', $_GET ) && $searchterm != "")
- $query->set("meta_query", $meta_query);
- };
- }
- add_filter( "pre_get_posts", "bedrooms_guests_search_query");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment