Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created January 12, 2019 22:32
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 billerickson/7c6d8aa17b9544fdcf76cb4474c73761 to your computer and use it in GitHub Desktop.
Save billerickson/7c6d8aa17b9544fdcf76cb4474c73761 to your computer and use it in GitHub Desktop.
<?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