X Features Cars Demo Power Plants Demo State Parks Demo Site Showcase Docs Tutorials Add-ons Buy

Debugging CSS-based templates

For CSS-based templates, FacetWP will automatically try to find the right query. This usually works great, but sometimes FacetWP needs some extra guidance on which query to use.

The WordPress Loop

FacetWP tries to automatically add a facetwp-template CSS class to an element surrounding the Loop. But due to a myriad of circumstances, sometimes it needs to be done manually.

If so, wrap the CSS class around both the if ( have_posts() ) and else statements, as shown below).

<div class="facetwp-template">
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <?php get_template_part( 'content', 'post' ); ?>
    <?php endwhile; else : ?>
        <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>
</div>

The file to edit depends on several factors. As a general rule:

Search page: search.php
Main archive: archive.php
Category archive: category.php
Blog home: home.php
WooCommerce shop: archive-product.php

See WP’s Template Hierarchy page

No results

FacetWP was unable to auto-detect the post listing

If you’re seeing this error, it’s because FacetWP can’t find a suitable query. This usually happens when there’s a custom WP_Query on a standard WordPress page. See the Usage section on the facetwp_is_main_query page for the solution.

Turn on debug mode

If FacetWP isn’t filtering correctly, it’s because FacetWP is using the wrong query.

To find which query FacetWP is using, go to Settings > FacetWP > Settings, and turn on Debug Mode.

Finding the query

Browse to your facet listing, open the browser console, and type in:

FWP.settings.debug;

This will return lots of debugging data, including the query arguments and SQL.

debugging

Ignore irrelevent queries

Let’s say you’ve determine that FacetWP is incorrectly using a query with post_type = edd_wish_list. We’ll just tell FacetWP to ignore the query, using the facetwp_is_main_query filter.

add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
    if ( 'edd_wish_list' == $query->get( 'post_type' ) ) {
        $is_main_query = false;
    }
    return $is_main_query;
}, 10, 2 );