facetwp preload variables

djrmom

{{gist file=”custom-hooks.php” lang=”php”}}
<?php
/** preload facet for specific page **/
add_filter( ‘facetwp_preload_url_vars’, function( $url_vars ) {
if ( ‘my_page’ == FWP()->helper->get_uri() ) {
if ( empty( $url_vars ) ) { // or check a specific facet empty( $url_vars[‘some_facet’] )
$value = ‘something’ // ‘something’ should be looked up for ‘my_page’
$url_vars[‘some_facet’] = array( $value );
}
}
return $url_vars;
} );

/** look up post from get_uri **/
add_filter( ‘facetwp_preload_url_vars’, function( $url_vars ) {
if ( empty( $url_vars ) ) { // or check a specific facet empty( $url_vars[‘some_facet’] )
$post = get_page_by_path( FWP()->helper->get_uri() );
$value = ‘something’ // ‘something’ should be looked up from $post or $post->ID
$url_vars[‘some_facet’] = array( $value );
}
return $url_vars;
} );
{{/gist}}