// 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$cf){

array_push($meta_query,array(

'key'=>$cf,

'value'=>$searchterm,

'compare'=>'LIKE'

));

}

$query->set("meta_query",$meta_query);

};

}

add_filter("pre_get_posts","custom_search_query");

add_action("save_post","add_title_custom_field");

functionadd_title_custom_field($postid){

// since we removed the "s" from the search query, we want to create a custom field for every post_title. I don't use post_content, if you also want to index this, you will have to add this also as meta field.