-
-
Save billerickson/7c6d8aa17b9544fdcf76cb4474c73761 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Empty search redirect | |
* https://www.billerickson.net/advanced-search-with-searchwp-and-facetwp/#empty-search | |
*/ | |
function ea_empty_search_redirect( $query ) { | |
if( $query->is_main_query() && ! is_admin() && $query->is_search() && empty( $query->query['s'] ) ) { | |
wp_redirect( home_url( 'search' ) ); | |
exit; | |
} | |
} | |
add_action( 'pre_get_posts', 'ea_empty_search_redirect' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment