#1151

Dominykas
Keymaster

Hi David,

Please excuse the delayed reply. It took me some time to resolve your questions.

1) I’m glad to hear that!

2) You’re right about loop-single-topic.php. You need to pass the topic average rating to elm_readonly_rating_form(). There’s an issue in our documentation. Sorry for that. We’ll fix this ASAP.

The following code works for me:

  • < ?php // Get topic average rating $topic_average = elm_ratings_get_average( get_the_ID() ); // Display read-only rating form elm_readonly_rating_form( $topic_average ); ?>
  • You need to get the topic average rating by using elm_ratings_get_average( get_the_ID() ); get_the_ID() is the current topic ID in the loop, then pass it to elm_readonly_rating_form();

    3) Got it. I wrote a function for this purpose. You need to hook into posts_clauses and change the SQL query for topics.

    The following code works for me. You should add this code to the theme’s functions.php file.

    function rm_sort_bbp_topics_by_rating( $pieces, $query ) {
    	// Apply this only for bbPress topics
    	if($query->query_vars['post_type'] == 'topic') {
    		global $wpdb;
    
    		// Remove: AND ( wp_postmeta.meta_key = '_bbp_last_active_time' )
    		$pieces['where'] = trim(substr($pieces['where'], 0, strpos($pieces['where'], "AND (")));
    
    		// Also join to _average_page_rating meta_key
    		$pieces['join'] = "INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id AND wp_postmeta.meta_key = '_average_page_rating' )";
    
    		// Sort by highest rating
    		$pieces['orderby'] = "wp_postmeta.meta_value DESC";
    	}
    
    	return $pieces;
    }
    
    add_filter( 'posts_clauses', 'rm_sort_bbp_topics_by_rating', 10, 2 );
    

    See screenshot: https://s11.postimg.org/goqgtbntv/Screen_Shot_2016_12_01_at_18_43_45.png

    Hope this helps! :) Please let me know if you have any more questions.