• Resolved LazyLuv

    (@lazyluv)


    Hello,

    I’m very new at the coding in WordPress thing, so I don’t fully understand the language and lingo. However, with that being said I am trying to place a view count on my posts so the visitor sees how many times a video has been viewed.

    Here is my issue.

    When I place

    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);
        }
    }

    in functions.php via child theme. Then I paste

    <?php setPostViews(get_the_ID()); ?>

    in single.php,

    and <?php echo getPostViews(get_the_ID()); ?>

    in content.php,

    I’ll get a return, but it’s only on the front end or the frontpage where the posts are. I don’t see a view count on the actual post. What am I doing wrong?

    I’ve tried to paste the code in single-tmpl.php, content.php, etc. I’m so confused.

    Thanks for your time.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi there,

    You will need to customize the theme for this. You can also consult with a developer.

    Thanks!

    Thread Starter LazyLuv

    (@lazyluv)

    After doing some digging, I was able to complete the task. It was also fun learning a little more about the language too. Be well!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘View Count Only Shows On Frontpage, Not On Posts’ is closed to new replies.