daily pastebin goal
76%
SHARE
TWEET

Untitled

a guest Aug 12th, 2017 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function setPostViews($postID) {
  2.     $count_key = 'views';
  3.     $count = get_post_meta($postID, $count_key, true);
  4.     if($count==''){
  5.         $count = 0;
  6.         delete_post_meta($postID, $count_key);
  7.         add_post_meta($postID, $count_key, '0');
  8.     }else{
  9.         $count++;
  10.         update_post_meta($postID, $count_key, $count);
  11.     }
  12. }
  13.    
  14. function setPostViews($postID) {
  15.  
  16.     $user_ip = $_SERVER['REMOTE_ADDR']; //retrieve the current IP address of the visitor
  17.     $key = $user_ip . 'x' . $postID; //combine post ID & IP to form unique key
  18.     $value = array($user_ip, $postID); // store post ID & IP as separate values (see note)
  19.     $visited = get_transient($key); //get transient and store in variable
  20.  
  21.     //check to see if the Post ID/IP ($key) address is currently stored as a transient
  22.     if ( false === ( $visited ) ) {
  23.  
  24.         //store the unique key, Post ID & IP address for 12 hours if it does not exist
  25.         set_transient( $key, $value, 60*60*12 );
  26.  
  27.         // now run post views function
  28.         $count_key = 'views';
  29.         $count = get_post_meta($postID, $count_key, true);
  30.         if($count==''){
  31.             $count = 0;
  32.             delete_post_meta($postID, $count_key);
  33.             add_post_meta($postID, $count_key, '0');
  34.         }else{
  35.             $count++;
  36.             update_post_meta($postID, $count_key, $count);
  37.         }
  38.  
  39.  
  40.     }
  41.  
  42. }
  43.    
  44. set_transient( $key, $value, 60*60*24 );
  45.    
  46. 192.160.0.5x333
  47.    
  48. set_transient( $key, $value, 60*60*12 );
  49.    
  50. function setPostViews($postID) {
  51.  
  52.     //check if user not administrator, if so execute code block within
  53.     if( !current_user_can('administrator') ) {
  54.  
  55.        //all code goes here...
  56.  
  57.     }
  58.  
  59. }
  60.    
  61. function slzexploore_postview_set() {
  62.  
  63.     global $post;
  64.  
  65.     $post_types = array('post', 'slzexploore_tour', 'slzexploore_hotel');
  66.  
  67.     if( $post ) {
  68.  
  69.         $post_id = $post->ID;
  70.  
  71.         if( in_array(get_post_type(), $post_types) && is_single() ) {
  72.  
  73.             $count_key = 'slzexploore_postview_number';
  74.  
  75.             $count = get_post_meta( $post_id, $count_key, true );
  76.  
  77.             if( $count == '' ) {
  78.  
  79.                 $count = 0;
  80.  
  81.                 delete_post_meta( $post_id, $count_key );
  82.  
  83.                 add_post_meta( $post_id, $count_key, '0' );
  84.  
  85.             } else {
  86.  
  87.                 $count++;
  88.  
  89.                 update_post_meta( $post_id, $count_key, $count );
  90.  
  91.             }
  92.  
  93.         }
  94.  
  95.     }
  96.  
  97. }
RAW Paste Data
Top