<?php
/** changes depth and parent_ids
** to allow a hierarchy to start with
** first level children instead of top level parents
**/
add_filter( 'facetwp_index_row', function( $params ) {
if ( 'my_facet' == $params['facet_name'] ) { // 'my_facet' should be replaced with your facet name
if ( 1 > $params[ 'parent_id' ] ) { // this will be top level parents
$params[ 'facet_value' ] = ''; // don't index
} elseif ( 2 > $params[ 'depth' ] ) { // first level children need depth and parent id changed
$params[ 'parent_id' ] = 0;
$params[ 'depth' ] = 0;
} else { // other children just need depth adusted
$params[ 'depth' ] = $params[ 'depth' ] - 1;
}
}
return $params;
});