-
-
Save pankajpatel/94fa616c2d8faa9caa17 to your computer and use it in GitHub Desktop.
FacetWP - sort by average rating using the WP Job Manager Reviews plugin
This file contains 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 a "Rating" sort option | |
* | |
* @author David Nash <[email protected]> | |
*/ | |
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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment