combine plugin/theme search code

besides reducing duplication, it also fixes an undefined $fields
variable notice