facetwp custom reset to pre-selected

djrmom

{{gist file=”custom-hooks.php” lang=”php”}}
<?php
/** custom set a facet to a specfic value on FWP.reset() instead of clearing
** change ‘categories’ to the name of your facet and ‘post-formats’ to
** the value you want selected
**/
add_action( ‘wp_footer’, function() { ?>
<script>
(function($) {
if (‘object’ !== typeof FWP) {
return;
}
$(function() {
FWP.hooks.addAction(‘facetwp/reset’, function() {
FWP.facets[‘categories’] = [‘post-formats’];
});
});
})(jQuery)
</script>
<?php }, 100 );
{{/gist}}