Skip to:
Content
Pages
Categories
Search
Top
Bottom

view count in bbpress group forum doesn’t work

  • @qbow-admin

    Participant

    I’ve been using bbpress plugin to set up forums for my website’s users. Originally there is no function when it comes to ‘counting views’ of each post. So I added some codes according to this website’s advice.

    It works fine with general(sitewide) forums but when I made a group(buddypress function) and tried to integrate it with bbpress forum, the view count php code does not work in group forums. (Still, it works perfectly fine at sitewide forums)

    this is my code right now (wp-content/plugins/bbpress/templates/default/bbpress/loop-single-topic.php)

    <li class="bbp-topic-voice-count">
        <?php 
    
    if( !function_exists('get_wpbbp_post_view') ) :
    // get bbpress topic view counter
    function get_wpbbp_post_view($postID){
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        return "0";
    }
    return $count;
    }
    function set_wpbbp_post_view($postID) {
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if( $count == '' ){
        add_post_meta($postID, $count_key, '1');
    } else {
        $new_count = $count + 1;
        update_post_meta($postID, $count_key, $new_count);
    }
    }
    endif;
    
    if( !function_exists('add_wpbbp_topic_counter') ) :
    // init the view counter in bbpress single topic
    function add_wpbbp_topic_counter() {
    global $wp_query;
    $bbp = bbpress();
    $active_topic = $bbp->current_topic_id;
    set_wpbbp_post_view( $active_topic );
    }
    add_action('bbp_template_after_single_topic', 'add_wpbbp_topic_counter');
    endif;
    
    echo get_wpbbp_post_view( bbp_get_topic_id() ); ?>
    </li>
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Skip to toolbar