2014-10-10 112 views
2

我正在使用下面的代碼,但不知道如何添加兩個單獨的搜索表單,僅在父類別中搜索產品。無論是product_parent_cat_floralproduct_parent_cat_rentalswoocommerce僅搜索基於主體類別的父類別產品

  <?php 
       $classes = get_body_class(); 
       if (in_array('product_parent_cat_rentals',$classes)) { 
      ?> 

       //rentals search form would go here 

      <?php } else { ?> 

       //flowers search form would go here 

      <?php } ?> 

我可以編輯該搜索表單以某種方式使它只此時,相應的父類中搜索產品?

<form role="search" method="get" id="searchform" action="http://botanicaevents.com/rentals/"> 
     <div> 
      <label class="screen-reader-text" for="s">Search for:</label> 
      <input type="text" value="" name="s" id="s" placeholder="Search for products" /> 
      <input type="submit" id="searchsubmit" value="Search" /> 
      <input type="hidden" name="post_type" value="product" /> 
     </div> 
    </form> 

回答

1

我想你可以簡單地使用:

<input type="hidden" name="product_cat" value="rentals" /> 

所以你的搜索查詢變爲:

?s=some+search+string&post_type=product&product_cat=rentals 

額外限制rentals產品類別內的搜索。

相關問題