FacetWP index multiple parents

<?php
// For an explanation and more elaborate example see:
// https://facetwp.com/help-center/developers/hooks/indexing-hooks/facetwp_index_row/#index-only-children-of-one-or-more-parents

add_filter( 'facetwp_index_row', function( $params, $class ) {
	if ( 'sub_categories' == $params['facet_name'] ) { // change sub_categories to name of your facet
		$parents = array( 18, 20 ); // change to ids of your parent terms
		if ( ! isset( $params['parent_id'] ) || ! in_array( $params['parent_id'], $parents ) ) {
			$params['facet_value'] = ''; // skip indexing
		}
	}
	return $params;
}, 10, 2 );