facetwp add tags to category facet

djrmom

{{gist file=”custom-hooks.php” lang=”php”}}
<?php

add_filter( ‘facetwp_indexer_row_data’, function( $rows, $params ) {
if ( ‘cases_topics’ == $params[‘facet’][‘name’] ) {
$post_id = $params[‘defaults’][‘post_id’];
$tags = get_tags( $post_id );
if ( !empty( $tags ) ) {
foreach ( $tags as $tag ) {
$new_row = $params[‘defaults’];
$new_row[‘facet_source’] = ‘tax/post_tag’;
$new_row[‘facet_value’] = $tag->slug;
$new_row[‘facet_display_value’] = $tag->name;
$new_row[‘term_id’] = $tag->term_id;
$rows[] = $new_row;
}
}
}
return $rows;
}, 10, 2 );
{{/gist}}