2014-10-10 114 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产品类别内的搜索。

相关问题