Skip to:
Content
Pages
Categories
Search
Top
Bottom

view count in bbpress group forum doesn’t work


  • qbow-admin
    Participant

    @qbow-admin

    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)

  • qbow-admin
    Participant

    @qbow-admin

    what do u mean, ok..?


    Robkk
    Moderator

    @robkk

    @qbow-admin

    its a spammer ignore it.

    as for your topic, I haven’t dabbled deep with BuddyPress and maybe later today I will play with it and see what I can come up with.


    qbow-admin
    Participant

    @qbow-admin

    @Robkk
    oh, i see.
    Thanks! I’m gonna be waiting for your brilliant solution 🙂


    qbow-admin
    Participant

    @qbow-admin

    anybody????


    Robkk
    Moderator

    @robkk

    @qbow-admin

    Yeah I don’t know what to tell you it just doesn’t work.

    I tried that way that you had views , and some other views plugins that didn’t work also.


    qbow-admin
    Participant

    @qbow-admin

    @Robkk

    I see. thanks for trying, tho.
    I just don’t understand why it doesn’t work only in ‘group forums’ 🙁


    Robkk
    Moderator

    @robkk

    @qbow-admin

    yeah it’s weird, I couldn’t figure it out.


    imagecrisis
    Participant

    @imagecrisis

    Try changing:

    $active_topic = $bbp->current_topic_id;

    …to:

    $active_topic_id = $bbp->topic_query->post->ID;

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