Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 1 replies (of 1 total)
  • @caveman92

    Member

    Here’s the code I used; It worked somehwat, but was giving me the same view count for each topic post. I got the sense that buddypress topics all have the same post id… that’s probably why it was giving me the same count for all… any thoughts?

    THIS WENT IN FUNCTIONS.PHP
    function getPostViews($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 View”;
    }
    return $count.’ Views’;
    }

    function setPostViews($postID) {
    $count_key = ‘post_views_count’;
    $count = get_post_meta($postID, $count_key, true);
    if($count==”){
    $count = 0;
    delete_post_meta($postID, $count_key);
    add_post_meta($postID, $count_key, ‘0’);
    }else{
    $count++;
    update_post_meta($postID, $count_key, $count);
    }
    }

    THIS WENT IN THE INDIVIDUAL FORUM-TOPIC FILE
    Note that I put open/close bracket for triangular brackets:

    open bracket
    ?php
    setPostViews(get_the_ID());
    ?
    close bracket

    AND THIS GOES WHERE I WANT THE NUMBER OF VIEWS TO SHOW:
    open bracket
    ?php
    echo getPostViews(get_the_ID());
    ?
    close bracket

Viewing 1 replies (of 1 total)
Skip to toolbar