Skip to content

Instantly share code, notes, and snippets.

@pattonwebz
Created December 5, 2022 20:28
Show Gist options
  • Select an option

  • Save pattonwebz/6fa4bbbc7fc0a6c6e86282715321cbbf to your computer and use it in GitHub Desktop.

Select an option

Save pattonwebz/6fa4bbbc7fc0a6c6e86282715321cbbf to your computer and use it in GitHub Desktop.
Disable core search query handling
<?php
function disable_core_search_query_handling($query, $error = true) {
if (is_search() && !is_admin()) {
$query->is_search = false;
$query->query_vars['s'] = false;
$query->query['s'] = false;
// to error
if ($error === true) {
$query->is_404 = true;
}
}
}
add_action('parse_query', __NAMESPACE__ . '\disable_core_search_query_handling');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment