Last active
April 19, 2018 15:27
-
-
Save djrmom/c892201e5a99831b27bfa2ad841e2768 to your computer and use it in GitHub Desktop.
facetwp preload variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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