0815

Du musst dich anmelden um Beiträge und Themen zu erstellen. Einloggen · Registrieren

Disable WordPress Search Functionality

Disabling the WordPress search functionality is as simple as adding the following code to your functions.php file:

function fb_filter_query($query, $error = true) {
 
	if (is_search()) {
		$query->is_search = false;
		$query->query_vars[s] = false;
		$query->query[s] = false;
 
		// to error
		if ($error == true)
			$query->is_404 = true;
	}
}
if (!is_admin()) {
	add_action('parse_query', 'fb_filter_query');
	add_filter('get_search_form', create_function('$a', "return null;"));
}

In place, this code will disable the search form for your theme while leaving search functionality intact for the Admin area. As is, the $error variable is set to TRUE, which causes the function to display the theme’s error page. Setting this variable to FALSE will prevent the error message and keep the user on the same page.

Source: WPengineer




0