Skip to content

Instantly share code, notes, and snippets.

@djrmom
Last active April 19, 2018 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djrmom/3286304a09092df8fc4d6086b605826a to your computer and use it in GitHub Desktop.
Save djrmom/3286304a09092df8fc4d6086b605826a to your computer and use it in GitHub Desktop.
<?php
/**
* filter html for sort output to output radio buttons
*/
add_filter( 'facetwp_sort_html', function( $html, $params ) {
$html = '';
foreach ( $params['sort_options'] as $key => $atts ) {
$html .= '<input type="radio" name="custom-sort" value="' . $key . '">' . $atts['label'] . '<br>';
}
return $html;
}, 10, 2 );
/**
* add js to custom handle selections of sort radio button
*/
add_action( 'wp_head', function() {
?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
$('input[type=radio][name=custom-sort]').change(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