Created
November 30, 2011 14:23
-
-
Save danielbachhuber/1409229 to your computer and use it in GitHub Desktop.
Handling WordPress search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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