0

I have a site with two search fields, one on a page called 'blog' and one on a page called 'archive'. I am using <?php get_search_form(); ?> to call the forms. All of the sites posts are either put in the blog category or the archive category and I use those to organize everything. I have the searches working with this in my functions.php file, which is working perfectly to break up the two searches:

function archive_search_filter( $query ) {
    if ( !is_admin() && $query->is_search() && $query->is_main_query() && 
wp_get_referer() == "http://localhost:8080/archive/" ) {
$query->set( 'category__not_in' , '9' ); 
    }
    if ( !is_admin() && $query->is_search() && $query->is_main_query() && 
wp_get_referer() == "http://localhost:8080/blog/" ) {
$query->set( 'category__not_in' , '8' );
    }
}
add_filter( 'pre_get_posts', 'archive_search_filter' );

Both of the results pages for the searches go to search.php but I'm wondering if there is a way to send one to search.php and one to another template that I create depending on which category search it is coming from.

0

Yes you can. From the Wordpress Codex:

function my_page_template_redirect() {
    if( is_page( 'goodies' ) && ! is_user_logged_in() ) {
        wp_redirect( home_url( '/signup/' ) );
        die;
    }
}
add_action( 'template_redirect', 'my_page_template_redirect' );

Looking at your code, I think you can figure out how to adjust this to your situation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.