wp post view counter not work

Discussion in 'WordPress' started by Tuhin1234, Jul 29, 2016.

  1. #1
    it work only new post but alredy published post not work


    // function to display number of posts.
    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";
    }
    return $count.'';
    }
    
    // function to 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);
    }
    }
    Code (JavaScript):
     
    Tuhin1234, Jul 29, 2016 IP
  2. Tuhin1234

    Tuhin1234 Active Member

    Messages:
    178
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #2
    fix it
     
    Tuhin1234, Jul 29, 2016 IP