This topic contains 4 replies, has 2 voices, and was last updated by  Dominykas 3 years ago.

  • Creator
  • #1143


    Hi, thank you for your plugin!

    I have 3 questions about the plugin. I like to use it to rate bbpress-topics, so i also installed the bbpress-addon.

    1) how can I limit rating only to topics? So not to replies. My quick solution would be to add css display:none; but there might be a better solution.

    2) how can I show the topic-rating in the forum list? I’d like to show the star-rating in stead of the voices. Probably add some code to some template?

    3) If 2 would become posible, i’d like to order the topics in the listing on rating. Would that be possible?

    I would really appreciated your time on this!

  • Author
  • #1144


    Hi David,

    Thank you for asking!

    1) We had the same question a few weeks ago. It’s pretty easy to turn off ratings for bbPress replies, but you’ll need to add a few lines of code to your theme’s functions.php file. See a detailed information here:

    2) We have some template functions to output the rating form. You can find them here: , but you’ll need to add it in the right place (bbPress forum list template file). I would be happy to help you with this, but I need to get your theme “Kleo”. Would you like to send it to me?

    3) I think so. By clicking on “Voices” column or adding some sort of dropdown above the forum list?

    Please let me know if you have any more questions! :)

  • #1148


    Hi David,

    Have you managed to add the rating form to bbPress?

  • #1150


    Hi Dominykas,

    Thanks so much for your reply. It took me some time to get back on this problem as I was struggling with some other problems ;)

    1) It worked! Allthough the first instruction on adding the hook name “bbp_theme_after_reply_content” to Rating form location resulted in double ratings.. So I removed the hook name again and now its fine.

    2) Thanks for the pointing in the right direction. I think I should modify bbpress/loop-single-topic.php but if I add elm_readonly_rating_form() at the place of voices, I only see one empty raring.. I think that the rating dows not know what rating to show.. If you would have a look at it, that would be awesome, I have put the bbpress-template-files (I think that is the only files you need? ) at this location:

    3) I am not sure if you understand correctly. I mean to sort the topics within the forum-page by default on rating, so if you open the page, like, the sticky is at the top, but after that, the best rated topic is showed on top after that, and the seconde rated topic after that, etc.

    Thanks so much for helping!

  • #1151


    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:

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

The topic ‘[Solved] Rating Topics for bbpress’ is closed to new replies.