I'm working on a custom filtering to pass the parameters to the page url when user selects a value and clicks the search button. However I can't get the proper output parameters.
in order for the filtering to work i need a format which looks something like this:
shop/?filter_tyre-width=22
What I get currently looks like this:
shop/?tyre_width=22
How do slot in the prefix filter_
after the ?
symbol?
<?php
$terms_width = get_terms("pa_tyre-width");
$terms_height = get_terms("pa_aspect-ratio");
$filter_width = isset( $_GET['tyre_width'] ) ? esc_attr( $_GET['tyre_width'] ) : '';
$filter_height = isset( $_GET['aspect-ratio'] ) ? esc_attr( $_GET['aspect-ratio'] ) : '';
if ( '' == get_option( 'permalink_structure' ) ) {
$form_action = remove_query_arg( array( 'page', 'paged' ), add_query_arg( $wp->query_string, '', home_url( $wp->request ) ) );
} else {
$form_action = preg_replace( '%\/page/[0-9]+%', '', home_url( trailingslashit( $wp->request ) ) );
}
$new_link = add_query_arg( 'filtering', '1', $form_action );
//."filtering=1"
echo $new_link;
echo '<form method="get" action="' . $new_link . '" class="col-md-12 clearfix">';
echo '
<div class="col-md-3">
<label for="">Width</label>
<div class="input-group select-large">
<select id="tyre_width" name="tyre_width">
<option>Select Width</option>
';
foreach ( $terms_width as $term_width ) {
echo '
<option value="' . $term_width->name . '"> ' . $term_width->name . '</option>
';
}
echo '</select></div></div>';
echo '
<div class="col-md-3">
<label for="">Height</label>
<div class="input-group select-large">
<select id="aspect-ratio" name="aspect-ratio">
';
foreach ( $terms_height as $term_height ) {
echo '
<option value="' . $term_height->name . '"> ' . $term_height->name . '</option>
';
}
echo '</select></div></div>';
echo '
<div class="col-md-3">
<div class="input-group search-btn">
<label for="submit">Start Search!</label>
<input type="submit" placeholder="Go" value="Search">
</div>
</form>';
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire