FacetWP – Pre-select a facet choice on initial pageload

mgibbs189

{{gist file=”functions.php” lang=”php”}}
<?php

function modify_selected_values( $args, $class ) {
if ( 1 == (int) $class->ajax_params[‘first_load’] ) {
foreach ( $class->facets as $k => $facet ) {
if ( ‘langues_offertes’ == $facet[‘name’] ) {
FWP()->facet->facets[ $k ][‘selected_values’] = array( ‘francais’ );
break;
}
}
}
return $args;
}
add_filter( ‘facetwp_query_args’, ‘modify_selected_values’, 10, 2 );
{{/gist}}