Advertisement
firoze

post view count

Jun 22nd, 2015
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. // post view count
  2.  
  3. // functions.php
  4. function getPostViews($postID){
  5. $count_key = 'post_views_count';
  6. $count = get_post_meta($postID, $count_key, true);
  7. if($count==''){
  8. delete_post_meta($postID, $count_key);
  9. add_post_meta($postID, $count_key, '0');
  10. return "0 View";
  11. }
  12. return $count.' Views';
  13. }
  14. function setPostViews($postID) {
  15. $count_key = 'post_views_count';
  16. $count = get_post_meta($postID, $count_key, true);
  17. if($count==''){
  18. $count = 0;
  19. delete_post_meta($postID, $count_key);
  20. add_post_meta($postID, $count_key, '0');
  21. }else{
  22. $count++;
  23. update_post_meta($postID, $count_key, $count);
  24. }
  25. }
  26.  
  27. ===============================================================================================
  28.  
  29.  
  30. // where will be didplay
  31.  
  32. <?php echo getPostViews(get_the_ID()); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement