Skip to:
Content
Pages
Categories
Search
Top
Bottom

bbp_get_user_topic_count returns incorrect number


  • Anonymous User 18731058
    Inactive

    @anonymized-18731058

    I’m testing out bbPress on my development site, and on the profile page, both bbp_get_user_topic_count and bbp_get_user_reply_count are returning incorrect numbers for all users. When I delete all topics, on my admin account I get a topic count of 1 and reply count of 7. When I test it out on a new user, it starts correctly at 0, but as soon as I create a new topic, the topic count jumps to 2. When I create a new reply, the reply count also jumps to 2. When I delete the topic, I get a topic and reply count of 1. I’ve tried the recount tool in Tools > Forums, but it’s not fixing the issue.

Viewing 3 replies - 1 through 3 (of 3 total)

  • Robin W
    Moderator

    @robin-w

    yes, this has been happening for a while (it happens on this site!) , and I’ve not got round to looking at why until you posted (I am a bbpress user who helps out here, not one of the bbpress authors).

    I’ve just dug into the code and created a trac fix ticket for it

    https://bbpress.trac.wordpress.org/ticket/3429#ticket

    in the meantime, this code fixes the problem

    add_filter ('bbp_bump_user_topic_count' , 'rew_new_topic_count', 10 , 4) ;
    
    function rew_new_topic_count ($user_topic_count, $user_id, $difference, $count) {
    	//check if count is 2 and should be 1 by seeing if user topic count is empty!!
    	if ($user_topic_count==2 && empty (bbp_get_user_topic_count( $user_id, true )) )$user_topic_count = 1 ;
    return $user_topic_count ;	
    }
    
    add_filter ('bbp_bump_user_reply_count' , 'rew_new_reply_count', 10 , 4) ;
    
    function rew_new_reply_count ($user_reply_count, $user_id, $difference, $count) {
    	//check if count is 2 and should be 1 by seeing if user topic count is empty!!
    	if ($user_reply_count==2 && empty (bbp_get_user_reply_count( $user_id, true )) )$user_reply_count = 1 ;
    return $user_reply_count ;	
    }

    Put this in your child theme’s function file –

    ie wp-content/themes/%your-theme-name%/functions.php

    where %your-theme-name% is the name of your theme

    or use

    Code Snippets


    Anonymous User 18731058
    Inactive

    @anonymized-18731058

    Hi Robin,
    Unfortunately, the code you’ve provided isn’t working for me. However, bbp_get_user_topic_count_raw and bbp_get_user_reply_count_raw work fine, so I’ve replaced the functions using JavaScript.

    <?php
    $topicCount = bbp_get_user_topic_count_raw(wp_get_current_user()->ID);
    $replyCount = bbp_get_user_reply_count_raw(wp_get_current_user()->ID);
    ?>
    
    <script>
    var topicCount = document.querySelector('.bbp-user-topic-count');
    var replyCount = document.querySelector('.bbp-user-reply-count');
    if(topicCount){topicCount.innerHTML = 'Topics Created: ' + '<?php echo $topicCount ?>'}
    if(replyCount){replyCount.innerHTML = 'Replies Created: ' + '<?php echo $replyCount ?>'}
    </script>

    Robin W
    Moderator

    @robin-w

    🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar