Index only top-level taxonomy terms

If you have a hierarchical taxonomy, sometimes you may want to show only top-level terms.¬†Add this code to your theme’s functions.php file, replace “categories” with your facet name, and Re-index.

function index_top_level_terms( $params, $class ) {
    if ( 'categories' == $params['facet_name'] ) {
        if ( 0 < $params['depth'] ) {
            return false; // don't index child terms
        }
    }
    return $params;
}
add_filter( 'facetwp_index_row', 'index_top_level_terms', 10, 2 );