Advertisement
Barbareshet

Get / Set post meta "views"

May 8th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. // Get Post Meta
  2. function getPostViews($postID){
  3.  
  4.     $count_key = 'post_views_count';
  5.     $count = get_post_meta($postID, $count_key, true);
  6.     if($count==''){
  7.         delete_post_meta($postID, $count_key);
  8.         add_post_meta($postID, $count_key, '0');
  9.         return _e('0 <i class="fa fa-eye" aria-hidden="true"></i><span class="sr-only">מספר צפיות</span>');
  10.     }
  11.     return $count.' <i class="fa fa-eye" aria-hidden="true"></i><span class="sr-only">מספר צפיות</span>';
  12. }
  13.  
  14. //Set Post Meta
  15. function setPostViews($postID) {
  16.     $count_key = 'post_views_count';
  17.     $count = get_post_meta($postID, $count_key, true);
  18.     if($count==''){
  19.         $count = 0;
  20.         delete_post_meta($postID, $count_key);
  21.         add_post_meta($postID, $count_key, '0');
  22.     }else{
  23.  
  24.         $count++;
  25.         update_post_meta($postID, $count_key, $count);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement