facetwp force query args

djrmom

{{gist file=”custom-hooks.php” lang=”php”}}
<?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 );
{{/gist}}