Last active
February 16, 2018 21:01
-
-
Save djrmom/7ac89af1130b3a96b27b401c40fb9bb5 to your computer and use it in GitHub Desktop.
facetwp force query args
This file contains 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 | |
/** to use this make sure all queries to be used | |
** for facets have 'facetwp' => true in query args, including the | |
** query args setting in a facetwp template | |
**/ | |
// add 'facetwp' => false anytime it is not already set | |
add_action( 'pre_get_posts', function( $query ) { | |
if ( ! isset( $query->query_var['facetwp'] ) ) { | |
$query->set( 'facetwp', false ); | |
} | |
return $query; | |
}); | |
// use 'facetwp' query arg to determine main query | |
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) { | |
if ( isset( $query->query_vars['facetwp'] ) ) { | |
$is_main_query = (bool) $query->query_vars['facetwp']; | |
} | |
return $is_main_query; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment