Search page redirect for WPGridBuilder

tdrayson

This function changes where the default search form redirects to.

This is useful if you are using the WPGridbuilder plugin and you want the search form to redirect and autopopulate your search facet on your blog page for example.

PHP

        <?php

function tct_redirect_search() {
	if ( is_search() && ! empty( $_GET['s'] ) ) {
		$post_type = get_post_type();
        $archive_url = get_post_type_archive_link($post_type);
        $search = 'search'; // Change with facet search slug 
        
        wp_redirect( $archive_url . '/?_' . $search .'=' . urlencode( get_query_var( 's' ) ) );
		exit();
	}	
}
add_action( 'template_redirect', 'tct_redirect_search' );
      
Copy

👋🏻 Weekly Tutorial Digest

I send out a weekly newsletter with links to new tutorials written in the last week, you can subscribe below.

Newsletter

🔒I won't send you spam, I promise