$meta_query = array(); if (!empty($grad)) { $meta_query[] = array( 'key' => 'ex_lokacija', 'value' => $grad , 'compare' => 'LIKE' ) } // and so on for each of your keys, then $args = array( 'post_type' => 'post', 'relation' => 'AND', 'meta_query' => $meta_query ) $searched_posts = new WP_Query( $args );