Last active
December 29, 2020 14:07
-
-
Save mgibbs189/01350ecaa74f3c7f967b2ea8e32c4ed6 to your computer and use it in GitHub Desktop.
FacetWP - pull in comment data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment