Skip to content

Instantly share code, notes, and snippets.

@phucdohong96
Created November 3, 2017 08:11
Show Gist options
  • Save phucdohong96/45d269506a0c250e8b1edf1d03ccf5b4 to your computer and use it in GitHub Desktop.
Save phucdohong96/45d269506a0c250e8b1edf1d03ccf5b4 to your computer and use it in GitHub Desktop.
Form submit link to facetwp filter
<?php
//resource_home_filter_function
function resource_home_filter_function() {
ob_start();
?>
<form method="get" action="/resources/" class="home_filter_form nobottommargin">
<div class="select_filter">
<select name='fwp_product_category' id='fwp_product_category' class='distributor_market' >
<option value='' selected='selected'>Document Categories</option>
<?php
$terms = get_terms( 'resource_category' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
foreach ( $terms as $term ) {
$category_name = $term->name;
$category_slug = $term->slug;
echo '<option value="'.$category_slug.'">'.$category_name.'</option>';
}
}
?>
</select>
</div>
<div class="select_filter">
<select name='fwp_document_type' id='fwp_document_type' class='distributor_product' >
<option value='' selected='selected'>Document Type</option>
<?php
$terms = get_terms( 'resource_type' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
foreach ( $terms as $term ) {
$category_name = $term->name;
$category_slug = $term->slug;
echo '<option value="'.$category_slug.'">'.$category_name.'</option>';
}
}
?>
</select>
</div>
<input class="btn btn-lg" type="submit" value="Find Resources" />
</form>
<script type="text/javascript">
jQuery(function(){
jQuery('form').submit(function(){
jQuery('select').each(function(){
if(jQuery(this).val()==''){
jQuery(this).attr('disabled','disabled');
}
})
})
})
</script>
<?php
wp_reset_postdata();
return ob_get_clean();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment