Skip to content

Instantly share code, notes, and snippets.

@djrmom
Last active February 16, 2018 21:01
Show Gist options
  • Save djrmom/7ac89af1130b3a96b27b401c40fb9bb5 to your computer and use it in GitHub Desktop.
Save djrmom/7ac89af1130b3a96b27b401c40fb9bb5 to your computer and use it in GitHub Desktop.
facetwp force query args
<?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