<?php
/**
* Pre-select facet choices in FacetWP.
*/
add_filter( 'facetwp_preload_url_vars', function( $url_vars ) {
$page = get_page_by_path( FWP()->helper->get_uri() ); // for "page" post type, other post types may need different checks
$value = get_field( 'somefield', $page->ID );
if ( !empty( $value ) ) {
if ( empty( $url_vars['somefacet'] ) ) {
$url_vars['somefacet'] = array( $value );
}
}
return $url_vars;
} );