FacetWP – pull in comment data

mgibbs189

{{gist file=”functions.php” lang=”php”}}
$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 );

{{/gist}}