Using a custom WP_Query

If you’re trying to show facets on a WP page template (containing a custom WP_Query), FacetWP probably won’t be able to auto-detect the query. Don’t worry, we can nudge FacetWP into using the correct query:

1. Add the facetwp query argument:

<?php
$args = array(
    'post_type' => 'event',
    'posts_per_page' => 10,
    'facetwp' => true, // we added this
);
$query = new WP_Query( $args );

2. Add the following facetwp_is_main_query hook:

add_filter( 'facetwp_is_main_query', function( $bool, $query ) {
    return ( true === $query->get( 'facetwp' ) ) ? true : $bool;
}, 10, 2 );

See Also

facetwp_is_main_query