Skip to content

Instantly share code, notes, and snippets.

@djrmom
Last active April 19, 2018 15:27
Show Gist options
  • Save djrmom/c892201e5a99831b27bfa2ad841e2768 to your computer and use it in GitHub Desktop.
Save djrmom/c892201e5a99831b27bfa2ad841e2768 to your computer and use it in GitHub Desktop.
facetwp preload variables
<?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;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment