HTML5 36
WP multiple search forms & result templates By micha on 26th July 2018 02:57:11 PM
  1. // Search Forms
  2.  
  3. <form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
  4. <input type="text" value="" name="s" id="s" />
  5. <input type="hidden" name="search-type" value="blog" />
  6. <input name="submit" type="submit" value="Go" />
  7. </form>
  8.  
  9. // Modifying The Search Template (search.php)
  10.  
  11. <?php
  12. if(isset($_GET['search-type'])) {
  13.    $type = $_GET['search-type'];
  14.    if($type == 'blog') {
  15.        load_template(TEMPLATEPATH . '/blog-search.php');
  16.    } elseif($type == 'products') {
  17.        load_template(TEMPLATEPATH . '/products-search.php');
  18.    }
  19. }
  20. ?>
  21.  
  22. // Creating The New Search Templates
  23.  
  24. <?php
  25. // blog-search.php
  26. $args = array( 'post_type' => 'post' );
  27. $args = array_merge( $args, $wp_query->query );
  28. query_posts( $args );
  29. ?>
  30.  
  31. <?php
  32. // products-search.php
  33. $args = array( 'post_type' => 'products' );
  34. $args = array_merge( $args, $wp_query->query );
  35. query_posts( $args );
  36. ?>

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.