Post view count won't count
-
Hi community.
I have an issue with my functions.php code snippet which is supposed to count the views on my posts, but it seems not to work. It is a code of snippet I recieved through a tutorial but it seems not to read to my database. The view count is saying 0 even though the post has been visited a few times. The code snippet looks as following:
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 views"; } return $count.' views'; } // Count post view 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); } }
Are anyone able to see or tell me what I have done wrong or is missing.
Thank you !
- The topic ‘Post view count won't count’ is closed to new replies.