FacetWP – indexer Reviewer plugin data

mgibbs189

{{gist file=”functions.php” lang=”php”}}
<?php

add_filter( ‘facetwp_index_row’, function( $params, $class ) {
if ( ‘rating’ == $params[‘facet_name’] ) {
$post_id = (int) $params[‘post_id’];

/**
* IMPORTANT
* he following line needs editing. How to grab the average rating via the post ID?
*/
$average_rating = get_the_average_rating( $post_id );

$params[‘facet_value’] = $average_rating;
$params[‘facet_display_value’] = $average_rating;
}
return $params;
}, 10, 2 );

{{/gist}}