Support » Plugins » Hacks » cookie in wordpress

  • i’m creating a post view counter function using cookie. when a user has viewed specific post. a cookie will be created with name is the post ID. Note: get_the_ID() only use within the loop.
    i have made:

    function post_view_count(){
    global $newcount;
    $count_key='post_views_count'; a name of custom field of post
    $count = get_post_meta($IDpost, $count_key, true); //i store post view counter in custom field of post.
    if (!isset($_COOKIE[$IDpost])) {
            update_post_meta($IDpost, $count_key, $newcount);
            setcookie($IDpost, 'viewed', time() + 1800);
        return $newcount;

    Then include this function in the place you wish to show post view count.
    This function work well on localhost, a cookie haved been created (i showed cookie to check). But it did not run on server.
    Can u help me?

  • The topic ‘cookie in wordpress’ is closed to new replies.