AnsPress Plugin – Search results page

5.76K viewsGeneralsearch results page
0

Hi,
Is it possible specify a ‘search results’ page? I have selected all the other pages I want to use (AnsPress – Options – Pages) but there is not option for the ‘search results’ page.
At present the search results are displayed on the default WP page template (which isn’t styled the same as my generated / designed pages) and it using the default sidebar widgets. Ideally I would like the search results page to look like my other designed pages.
Is it possible to specify a saved page to display the search results?
With thanks

Answered question
0

Hello,
Add below code to you theme functions.php:

function my_question_search( $template ) {    
  global $wp_query;   
  $post_type = get_query_var('post_type');   
  if ( $wp_query->is_search && $post_type == 'question' ) {
    return locate_template( 'search-question.php' );
  }   
  return $template;   
}
add_filter( 'template_include', 'my_question_search' );

Edited comment

Hi Rahul. Wow your answer was fast 🙂
Do I just add the code as it is? Or do I need to edit / update it to specify which page to display the ‘search results’?

Add to theme’s functions.php

Hi, I also had the same issue. When I search something, it redirects to the default wordpress search page. After that when I choose any category, it redirects to the homepage.

I added the code in the functions.php. But it is not working.

What I want:
I need the search results to be display in the same page.

You are viewing 1 out of 1 answers, click here to view all answers.