<?php
/** basic filter for pre-selecting a facet choice that corresponds to the current archive term
** ex. http://example.com/category/someterm/
** only works when term slug is the same as the facet value and
** is the last part of the url, in the above example 'someterm' is the term slug
** and will be the facet value when selected ?categories=someterm
**/
add_filter( 'facetwp_preload_url_vars', function( $url_vars ) {
if ( false !== strpos( FWP()->helper->get_uri(), 'category' ) ) { // change 'category' whatever the url is for the term archive
if ( empty( $url_vars['categories'] ) ) { // change 'categories' to name of the facet here and below
$term = basename( FWP()->helper->get_uri() );
$url_vars['categories'] = [ $term ];
}
}
return $url_vars;
} );