Gists

7 months ago
<?php
/** this will migrate old urls with sort value to new sort facet value
 ** if you have a facetwp_sort_options filter, you need to keep it
 ** sort option name/slug (value displayed in url) in the new sort facet needs to 
 ** match old sort
 **/

add_filter( 'facetwp_preload_url_vars', function( $url_vars ) {
    if ( ! empty( $url_vars['sort'] ) ) { 
        $url_vars['my_sort_facet'] = $url_vars['sort']; // change 'my_sort_facet' to name of your sort facet
    }
    return $url_vars;
});

add_action( 'facetwp_scripts', function() {
    ?>
    <script>
        document.addEventListener('facetwp-refresh', function() {
            if ( FWP.loaded ) {
                FWP.extras.sort = '';
            }
        });
    </script>
    <?php
}, 100 );