HTML5 56
WP Multiple Searchforms By micha on 15th February 2019 10:00:17 AM
  1. // Multiple forms with different hidden input post types of `search-type`
  2.  
  3. <div class="search-form">
  4.         <form action="<?php bloginfo('url'); ?>" id="searchform" method="get">
  5.                 <input type="text" id="s" name="s" value="" class="head-search-box" placeholder="<?php echo __('Suchbegriff eingeben', 'your_text_domain'); ?>"/>
  6.                 <input type="hidden" name="search-type" value="normal" />
  7.                 <button type="submit"><i class="fa fa-search"></i></button>
  8.         </form>
  9. </div>
  10.  
  11.  
  12. <div class="search-form events">
  13.   <form action="<?php bloginfo('url'); ?>" id="searchform" method="get">
  14.         <input type="text" id="s" name="s" value="" class="head-search-box" placeholder="<?php echo __('Aus- & Weiterbildung durchsuchen', 'your_text_domain'); ?>"/>
  15.         <input type="hidden" name="search-type" value="events" />
  16.         <button type="submit"><i class="fa fa-search"></i></button>
  17.   </form>
  18. </div>
  19.  
  20.  
  21.  
  22. // search.php
  23. <?php
  24. if(isset($_GET['search-type'])) {
  25.  $type = $_GET['search-type'];
  26.  if($type == 'normal') {
  27.    load_template(get_template_directory() . '/search-normal.php');
  28.  } elseif($type == 'events') {
  29.    load_template(get_template_directory() . '/search-events.php');
  30.  }
  31. }
  32. ?>
  33.  
  34. // search-normal.php
  35. // -> file with the regular search result output
  36.  
  37.  
  38. // search-events.php
  39. // -> limit the searchresults only for post_type `events`
  40.  
  41.  
  42. // custom args for query
  43. <?php
  44. $today             = date( 'Y-m-d', current_time( 'timestamp', 1 ) );
  45.  
  46. $args = array(
  47.   'post_type'           => 'event',
  48.   'orderby'             => 'meta_value',
  49.   'order'                       => 'asc',
  50.   'meta_key'            => 'start_date',
  51.   'meta_query'          => array(
  52.     'relation'          => 'OR',
  53.     array(
  54.       'key'                     => 'start_date',
  55.       'value'                   => $today,
  56.       'compare'         => '>=',
  57.       'type'                    => 'DATE',
  58.     ),
  59.     array(
  60.       'relation'                => 'AND',
  61.       array(
  62.         'key'                   => 'start_date',
  63.         'value'                 => $today,
  64.         'compare'       => '<=',
  65.         'type'                  => 'DATE',
  66.       ),
  67.       array(
  68.         'key'                   => 'end_date',
  69.         'value'                 => $today,
  70.         'compare'               => '>=',
  71.         'type'                  => 'DATE',
  72.       ),
  73.     ),
  74.   )
  75. );
  76.  
  77. $args = array_merge( $args, $wp_query->query );
  78. query_posts( $args );
  79.  
  80. ...

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.