Custom Search Query running on every page

You are missing the curly brackets {} around your query statements so the query is modified regardless of the if statement.

So try modifying your code to have something like

if( is_search() ) { 
  $fields="..."; 
  return $fields 
} 

same thing with your $join variable

Remember that while using if without brackets is acceptable for single statements, it is better to always use the curly brackets. Even if it’s only to make the code more consistent and easy to read for another coder (or even you in 6 months from now).

You’ll save an awful lot of time debugging errors that aren’t actually ones. A little bit like you just experienced with your issue here 🙂