View Count Only Shows On Frontpage, Not On Posts
-
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.
- The topic ‘View Count Only Shows On Frontpage, Not On Posts’ is closed to new replies.