<?php

/** for indexing multiple taxonomies and multiple post types within a single facet
 ** set datasource to post type **/

add_filter( 'facetwp_index_row', function( $params, $class ) {

	if ( 'YOUR_FACET == $params['facet_name'] ) { // make sure to change 'YOUR_FACET' to the name of your facet

		$post_id = $params['post_id']; // get the currrent post id

		// copy the params to a new variable so the original is preserved
		$new_params = $params;

        if ( 'post' == get_post_type( $post_id ) {
            $terms = get_the_terms( $post_id, 'category' )
        } elseif ( 'OTHER_POST_TYPE' == get_post_type( $post_id ) { // set name of post type
            $terms = get_the_terms( $post_id, 'OTHER_TAXONOMY' ) // set name of other taxonomy
        }
        
        if ( !is_wp_error() && !empty( $terms ) ) {
            foreach ( $terms AS $term ) {
                $new_params['term_id'] = $term->term_id;
                $new_params['facet_value'] = sanitize_title( $term->name );
		        $new_params['facet_display_value'] = $term->name;
                $class->insert( $new_params ); // adds the new row to facetwp index
            }
        }

		$params['facet_value'] = ''; // dont index post_type **/

	}
	return $params;
}, 10, 2 );