I'm trying to modify the product search form to include 3 "select fields" instead of the default textbox. Based on the option selected (the options are populated from the custom attributes that i've added to every product) the search should return me relevant products. Following is my code of "product-searchform.php" which I've placed in mystile theme folder to override the default search. I get all the posts(products) instead of specific. So somewhere my search isn't going right. Also where is the get_search_query() function's code?
<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>
<form role="search" method="get" class="woocommerce-product-search" action="<?php
echo esc_url(home_url('/'));
?>">
<label class="screen-reader-text" for="s"><?php
_e('Search for:', 'woocommerce');
?></label>
<input type="search" class="search-field" placeholder="<?php
echo esc_attr_x('Search Products…', 'placeholder', 'woocommerce');
?>" value="<?php
echo get_search_query();
?>" name="s" title="<?php
echo esc_attr_x('Search for:', 'label', 'woocommerce');
?>" />
<!-- Dropdown Product Category -->
<?php
if (class_exists('WooCommerce')):
?>
<?php
if (isset($_REQUEST['product_cat']) && !empty($_REQUEST['product_cat'])) {
$optsetlect = $_REQUEST['product_cat'];
} else {
$optsetlect = 0;
}
$args = array(
'show_option_all' => esc_html__('All Categories', 'woocommerce'),
'hierarchical' => 1,
'class' => 'cat',
'echo' => 1,
'value_field' => 'slug',
'selected' => $optsetlect
);
$args['taxonomy'] = 'product_cat';
$args['name'] = 'product_cat';
$args['class'] = 'cate-dropdown hidden-xs';
wp_dropdown_categories($args);
?>
<?php
endif;
?>
<?php
$terms = get_terms("pa_color");
$count = count($terms);
if ($count > 0) {
echo '<select class="select" id="brands" tabindex="11" name="pa_color">';
echo '<option value="brand">--Brand--</option>';
foreach ($terms as $term) {
echo '<option value="' . $term->slug . '">' . $term->slug . '</option>';
}
echo '</select>';
}
?>
<input type="submit" value="<?php
echo esc_attr_x('Search', 'submit button', 'woocommerce');
?>" />
<input type="hidden" name="post_type" value="product" />
</form>