2013-09-16 92 views
0

我試圖修改產品搜索表單以包含3個「選擇字段」而不是默認文本框。根據選擇的選項(選項從我添加到每個產品的自定義屬性中填充),搜索應返回相關產品。 以下是我放置在神祕主題文件夾中的「product-searchform.php」代碼,以覆蓋默認搜索。我得到所有的帖子(產品),而不是具體的。所以我的搜索不正確。還有get_search_query()函數的代碼在哪裏?在woocommerce中覆蓋產品搜索代碼不起作用

<form role="search" method="get" id="searchform" action="<?php echo esc_url(home_url('/' )); ?>"> 
<div> 
      <!-- Default Markup 
      <label class="screen-reader-text" for="s"><?php _e('Search for:', 'woocommerce'); ?></label> 
      <input type="text" value="<?php echo get_search_query(); ?>" name="s" id="s" placeholder="<?php _e('Search for products', 'woocommerce'); ?>" /> 
      <input type="submit" id="searchsubmit" value="<?php echo esc_attr__('Search'); ?>" /> 
      <input type="hidden" name="post_type" value="product" /> 
      */--> 
<?php 
$terms = get_terms("pa_country"); 
$count = count($terms); 
if($count > 0){ 
    echo '<select class="select" id="destination" tabindex="11" name="destination">'; 
    echo '<option value="Destination">--Destination--</option>'; 
    foreach($terms as $term){ 
     echo '<option value="' . $term->name . '">' . $term->name . '</option>'; 
    } 
    echo '</select>'; 
} 

$terms = get_terms("pa_days"); 
$count = count($terms); 
if($count > 0){ 
    echo '<select class="select" id="days" tabindex="11" name="days">'; 
    echo '<option value="Days">--Days--</option>'; 
    foreach($terms as $term){ 
     echo '<option value="' . $term->name . '">' . $term->name . '</option>'; 
    } 
    echo '</select>'; 
} 

$terms = get_terms("pa_budget"); 
$count = count($terms); 
if($count > 0){ 
    echo '<select class="select" id="budget" tabindex="11" name="budget">'; 
    echo '<option value="Budget">--Budget--</option>'; 
    foreach($terms as $term){ 
     echo '<option value="' . $term->name . '">' . $term->name . '</option>'; 
    } 
    echo '</select>'; 
} 
?> 
<input type="submit" id="searchsubmit" value="<?php echo esc_attr__('Search'); ?>" /> 
<input type="hidden" name="post_type" value="product" /> 
</div> 

回答