Created
August 28, 2017 13:58
-
-
Save djrmom/1321763f4e600456de371f3801824733 to your computer and use it in GitHub Desktop.
facetwp make select sort into a radio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* filter html for sort to output radio buttons | |
*/ | |
add_filter( 'facetwp_sort_html', function( $output, $params ) { | |
$output = '<div class="facetwp-sort-radio">'; | |
foreach ( $params['sort_options'] as $key => $atts ) { | |
$output .= '<input type="radio" name="sort" value="' . $key . '"> ' . $atts['label'] . '<br>'; | |
} | |
$output .= '</div>'; | |
return $output; | |
}, 10, 2 ); | |
/** | |
* js to handle: | |
* selecting the correct radio button on load | |
* updating the sort when a new button is selected | |
*/ | |
add_action( 'wp_head', function() { | |
?> | |
<script> | |
(function($) { | |
$(document).on('facetwp-loaded', function() { | |
if ('undefined' !== typeof FWP.extras.sort ) { | |
$( '.facetwp-sort-radio input:radio[name="sort"]').filter('[value="'+FWP.extras.sort+'"]').prop("checked", true); | |
} | |
}); | |
// Sorting | |
$(document).on('change', '.facetwp-sort-radio input', function() { | |
FWP.extras.sort = $(this).val(); | |
FWP.soft_refresh = true; | |
FWP.autoload(); | |
}); | |
})(jQuery); | |
</script> | |
<?php | |
}, 100 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awwwwwsommmmme!!!
Life Saver Thanks 💯