- // Multiple forms with different hidden input post types of `search-type`
- <div class="search-form">
- <form action="<?php bloginfo('url'); ?>" id="searchform" method="get">
- <input type="text" id="s" name="s" value="" class="head-search-box" placeholder="<?php echo __('Suchbegriff eingeben', 'your_text_domain'); ?>"/>
- <input type="hidden" name="search-type" value="normal" />
- </form>
- </div>
- <div class="search-form events">
- <form action="<?php bloginfo('url'); ?>" id="searchform" method="get">
- <input type="text" id="s" name="s" value="" class="head-search-box" placeholder="<?php echo __('Aus- & Weiterbildung durchsuchen', 'your_text_domain'); ?>"/>
- <input type="hidden" name="search-type" value="events" />
- </form>
- </div>
- // search.php
- <?php
- if(isset($_GET['search-type'])) {
- $type = $_GET['search-type'];
- if($type == 'normal') {
- load_template(get_template_directory() . '/search-normal.php');
- } elseif($type == 'events') {
- load_template(get_template_directory() . '/search-events.php');
- }
- }
- ?>
- // search-normal.php
- // -> file with the regular search result output
- // search-events.php
- // -> limit the searchresults only for post_type `events`
- // custom args for query
- <?php
- $today = date( 'Y-m-d', current_time( 'timestamp', 1 ) );
- $args = array(
- 'post_type' => 'event',
- 'orderby' => 'meta_value',
- 'order' => 'asc',
- 'meta_key' => 'start_date',
- 'meta_query' => array(
- 'relation' => 'OR',
- array(
- 'key' => 'start_date',
- 'value' => $today,
- 'compare' => '>=',
- 'type' => 'DATE',
- ),
- array(
- 'relation' => 'AND',
- array(
- 'key' => 'start_date',
- 'value' => $today,
- 'compare' => '<=',
- 'type' => 'DATE',
- ),
- array(
- 'key' => 'end_date',
- 'value' => $today,
- 'compare' => '>=',
- 'type' => 'DATE',
- ),
- ),
- )
- );
- $args = array_merge( $args, $wp_query->query );
- query_posts( $args );
- ...
Recent Pastes