<?php
add_filter( 'facetwp_indexer_row_data', function( $rows, $params ) {
/* index the comment ratings */
if ( 'comment_rating' == $params['facet']['source'] ) {
$post_id = (int) $params['defaults']['post_id'];
$comments = get_comments( [ 'post_id' => $post_id ] );
foreach ( $comments as $comment ) {
$new_row = $params['defaults'];
$new_row['facet_value'] = $comment->comment_content;
$new_row['facet_display_value'] = $comment->comment_content;
$rows[] = $new_row;
}
}
/* index the comment_authors */
elseif ( 'comment_author' == $params['facet']['source'] ) {
$post_id = (int) $params['defaults']['post_id'];
$comments = get_comments( [ 'post_id' => $post_id ] );
foreach ( $comments as $comment ) {
$new_row = $params['defaults'];
$new_row['facet_value'] = $comment->comment_author;
$new_row['facet_display_value'] = $comment->comment_author;
$rows[] = $new_row;
}
}
return $rows;
}, 10, 2 );