Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
Last active August 6, 2020 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mgibbs189/562a7d1225c6c41a5525 to your computer and use it in GitHub Desktop.
Save mgibbs189/562a7d1225c6c41a5525 to your computer and use it in GitHub Desktop.
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

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