Skip to content

Instantly share code, notes, and snippets.

@danielbachhuber
Created November 30, 2011 14:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielbachhuber/1409229 to your computer and use it in GitHub Desktop.
Save danielbachhuber/1409229 to your computer and use it in GitHub Desktop.
Handling WordPress search
<?php
/**
* Give the user a 404 if they do an internal WP search
*/
function db_unresolve_search() {
global $wp_query;
if ( $wp_query->is_search )
$wp_query->is_404 = true;
}
add_action( 'template_redirect', 'db_unresolve_search' );
/**
* Redirect the user to a new URL path if they do an internal WP search
*/
function db_redirect_search() {
global $wp_query;
if ( $wp_query->is_search ) {
wp_redirect( get_site_url( null, '/your-search-path/?s=' . urlencode( $wp_query->query_vars['s'] ) ) );
exit;
}
}
add_action( 'template_redirect', 'db_redirect_search' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment