Intuitive Custom Post Order
If you are using the Intuitive Custom Post Order plugin to order your taxonomy terms, use the code below to preserve that order for facets that use terms.
Setup
First, edit your facet (Settings > FacetWP) and set the “Sort by” option to “Term Order”.
Next, add the following code into your (child) theme’s functions.php, or use our Custom Hooks add-on:
add_filter( 'get_terms_args', function( $args, $taxonomies ) {
if ( isset( $args['term_order'] ) && 'order' !== $args['meta_key'] ) { // The second condition is needed to preserve WooCommerce ordering for product categories, by a termmeta field named "order".
$args['orderby'] = 'term_order';
}
return $args;
}, 10, 2 );
add_filter( 'get_terms_orderby', function( $orderby, $query_vars, $taxonomies ) {
return 'term_order' === $query_vars['orderby'] ? 'term_order' : $orderby;
}, 10, 3 );