2

On my current project, I have to create 2, distinct templates to receive 2 distinct search results of the same site.

Both researches are coming from different forms on different templates/pages.

Thing is, there is only one search.php file in Wordpress, and I don't think it's possible to create another one. (like search-taxonomy.php)

Is there a way to separate one search result of the other, and to then display the correct search page template in relation to which search form has been filled?

2 Answers 2

4

You could make a page template http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates

And then you could post some data via $_GET /search2/?search=xxx to that page and do a custom wp_query where you use 's=' . $_GET['search'] http://codex.wordpress.org/Class_Reference/WP_Query

Something like this:

$args = array(
   's' => $_GET['search']
);
$the_query = new WP_Query( $args );

// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
    echo '<li>';
    the_title();
    echo '</li>';
endwhile;
2
  • @ Rob Vermeer Thank you very much, even I made many changes but it gives me a great start to fix my problem Commented Feb 2, 2014 at 19:15
  • I face only a problem, my working pagination not working any more in that search page, I start my search page like below (I changed s with n to not stuck with normal search) if(!empty($_GET['n'])){ $args = array( 's' => $_GET['n'] ); $the_query = new WP_Query( $args ); and between the end of while and end of my if I added the pagination foodonia_pagination(); here is my_page Commented Feb 3, 2014 at 6:54
0

As far as I know it's not possible to run two separate searches using WP. What you could do is categorize them under separate headers in your results. It is possible to limit searches to a specific category.

Take a look and see if this plugin helps you at all: http://wordpress.org/extend/plugins/search-everything/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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