facetwp archive query main query

djrmom

{{gist file=”custom-hooks.php” lang=”php”}}
<?php
/** make sure facet always targets the archive query as the main query
** sometimes there is a mysterious extra query that is a duplicate
** of the main query
**/
add_filter( ‘pre_get_posts’, function( $query ) {
if ( $query->is_archive() && $query->is_main_query() ) {
$query->set( ‘facetwp’, true );
}
}, 9 );

add_filter( ‘facetwp_is_main_query’, function( $is_main_query, $query ) {
if ( $query->is_archive() && true !== $query->get( ‘facetwp’ ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
{{/gist}}