Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FacetWP - sort by average rating using the WP Job Manager Reviews plugin
<?php
/**
* Add a "Rating" sort option
*
* @author David Nash <david@davidnash.com.au>
*/
function custom_wpjmr_after_save_comment_review( $comment_id ) {
$wpjmr = WP_Job_Manager_Reviews::instance();
$wpjmr->review->save_rating_average_post_meta( $comment_id );
}
add_action( 'wpjmr_after_save_comment_review', custom_wpjmr_after_save_comment_review' );
function my_facetwp_sort_options( $options, $params ) {
$options['rating'] = array(
'label' => 'Rating',
'query_args' => array(
'orderby' => 'meta_value_num', // sort by numerical custom field
'meta_key' => '_average_rating', // required when sorting by custom fields
'order' => 'DESC', // descending order
)
);
return $options;
}
add_filter( 'facetwp_sort_options', 'my_facetwp_sort_options', 10, 2 );
@angelotdai
Copy link

angelotdai commented Aug 6, 2020

Can you do it with Reviewer Wordpress Plugin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment