質問
を作りたいものを実際に私の検索ボックスについて説明します。アイブ入力検索といくつかのチェック ボックスを検索結果をフィルター処理します
。
このような検索する必要があります: < br/> [Country1] と ([venue1] または [venue2]) と ([カテゴリ 1] や [category2]) と [topic1] と (BETWEEN $datefrom & $datetill)
マークアップ:
<form role="search" method="GET" id="searchform" action="<?php echo home_url( '/' ); ?>" > <input class="form-control" type="text" name="s" id="s" <?php if(is_search()) { ?>value="<?php the_search_query(); ?>" <?php } else { ?>value="Enter keywords …" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"<?php } ?> /><br /> <button class="btn btn-primary" type="submit" id="searchsubmit" value="Search" > Search </button> <h4>Countries</h4> <input name="location" value="Country1" type="radio" >Country1</label> <input name="location" value="Country2" type="radio" >Country2</label> <input name="location" value="Country3" type="radio" >Country3</label> <input name="location" value="Country4" type="radio" >Country4</label> <h4>Venues</h4> <input name="location" value="venue1" type="checkbox" >venue1</label> <input name="location" value="venue2" type="checkbox" >venue2</label> <input name="location" value="venue3" type="checkbox" >venue3</label> <input name="location" value="venue4" type="checkbox" >venue4</label> <h4>Custom taxonomy/Category</h4> <?php $categories = get_terms( 'eventcategory', array( 'orderby' => 'title', 'hide_empty' => 0, ) ); foreach ($categories as $va) { $cat_code = "<label>"; $cat_code .= "<input name='category_name' type='checkbox' value='"; $cat_code .= $va->name; $cat_code .= "' /> "; $cat_code .= $va->name; $cat_code .= "</label> "; echo $cat_code; } ?> <h4>Topic</h4> <input name="location" value="Topic1" type="radio" >Topic1</label> <input name="location" value="Topic2" type="radio" >Topic2</label> <input name="location" value="Topic3" type="radio" >Topic3</label> <input name="location" value="Topic4" type="radio" >Topic4</label> <h4>Date</h4> <input name="datefrom" id="datepicker1" type="text" class="form-control" /> <input name="datetill" id="datepicker2" type="text" class="form-control" /> </form>
functions.php
function search_filter($query) { if ( !is_admin() && $query->is_main_query() ) { if ( $query->is_search ) { $searchfield = $_GET['s']; $country = $_GET['location']; $venue_s = $_GET['venue']; $industry = $_GET['industry']; $datefrom = $_GET['datefrom']; $datetill = $_GET['datetill']; $filter_cat = $_POST['category_name']; $rel="OR"; $metaQuery = array( 'relation' => $rel, array( 'key' => 'location', 'value' => $country, 'compare' => 'IN' ), array( 'key' => 'venue', 'value' => $venue_s, 'compare' => '==' ), array( 'key' => 'industry', 'value' => $industry, 'compare' => '==' ), array( 'key' => 'datefrom', 'value' => array($datefrom, $datetill), 'compare' => 'BETWEEN' ) ); $query->set( 'meta_query' , $metaQuery ); } } } add_action('pre_get_posts','search_filter');
答え
検索 & フィルターのプラグインでこれを簡単に行うことができます
。
プラグイン url:
https://wordpress.org/plugins/search-filter/installation/
ドキュメント チェック アウト:
http://www.designsandcode.com/447/wordpress-search-filter-plugin-for-taxonomies/
texonomy で検索することができますこのプラグインでカスタム フィールドの記事カテゴリー ポストメタ等
この立てば
。
http://stackoverflow.com/questions/28217988/how-build-search-with-filtering-custom-taxonomy-and-custom-fields-in-wordpress