I’ve no time now, use this code only in a dev machine, because I didn’t tested!!!!
Use this only for testing
add_filter('posts_join_paged','yasr_join_paged');
add_filter('posts_where', 'yasr_where');
add_filter('posts_groupby', 'yasr_groupby');
add_filter('posts_orderby', 'yasr_posts_orderby');
function yasr_join_paged($join_paged_statement) {
if(is_home() && is_main_query()) {
global $wpdb;
return ", {$wpdb->prefix}yasr_log AS YL";
}
return $join_paged_statement;
}
function yasr_where($where) {
if(is_home() && is_main_query()) {
global $wpdb;
return " AND YL.post_id = {$wpdb->prefix}posts.ID";
}
return $where;
}
function yasr_groupby($groupby) {
if(is_home() && is_main_query()) {
global $wpdb;
return " YL.post_id, {$wpdb->prefix}posts.ID";
}
return $groupby;
}
function yasr_posts_orderby($orderby_statement) {
if(is_home() && is_main_query()) {
return " (ROUND(SUM(YL.vote) / COUNT(YL.post_id), 1)) DESC";
}
return $orderby_statement;
With the first filter, posts_join_paged
, we add the YASR table to the main query
With the second, posts_where
, we add the where clause, the post_ids must be the same.
With the third, posts_groupby
, we add the group by clause
With the last one, we put in the order by clause the average rating, sorting by higher.
This is to guide you if you’ve some coding skills.
I will work on this Monday.
Have a nice weekend,
Dario
-
This reply was modified 2 years, 10 months ago by dudo.