number of postviews not change in Main page
-
hi , i have strange problem
i use these codes to show number of post viewsin function.php :
<?php 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 "???? ??????"; } 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); } } ?>
and in single.php :
<?php setPostViews(get_the_ID()); ?><?php echo getPostViews(get_the_ID()); ?>
and in my index.php :
<?php echo getPostViews(get_the_ID()); ?>
the problem is the views counter change and increase when i go to post ( read more …) but when i came back to my home page the counter roll back to previews number and nothing changed !!!
whats the problem ?!?
and another strong thing is when i login as admin the real number of post views showed !! and everything works fine .
it seems the problem is with Guest users or something like that
[Do not post code using<strong>
but use the code button or backticks. Your code may have been damaged by the forum’s parser]
- The topic ‘number of postviews not change in Main page’ is closed to new replies.