Skip to content

Instantly share code, notes, and snippets.

@djrmom
Created April 17, 2020 14:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djrmom/482ac603d257ee351bc36acd8fbffff8 to your computer and use it in GitHub Desktop.
Save djrmom/482ac603d257ee351bc36acd8fbffff8 to your computer and use it in GitHub Desktop.
facetwp archive query main query
<?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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment