Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. IN FUNCTIONS.PHP
  2. ================
  3.  
  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";
  11. }
  12. return $count;
  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. IN SINGLE.PHP
  29. =============
  30.  
  31. <?php setPostViews(get_the_ID()); ?>
  32.  
  33.  
  34. IN DISPLAY TEMPLATE
  35. ===================
  36.  
  37. <?php echo getPostViews(get_the_ID()); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement