Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function setPostViews($postID) {
- $count_key = 'views';
- $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);
- }
- }
- function setPostViews($postID) {
- $user_ip = $_SERVER['REMOTE_ADDR']; //retrieve the current IP address of the visitor
- $key = $user_ip . 'x' . $postID; //combine post ID & IP to form unique key
- $value = array($user_ip, $postID); // store post ID & IP as separate values (see note)
- $visited = get_transient($key); //get transient and store in variable
- //check to see if the Post ID/IP ($key) address is currently stored as a transient
- if ( false === ( $visited ) ) {
- //store the unique key, Post ID & IP address for 12 hours if it does not exist
- set_transient( $key, $value, 60*60*12 );
- // now run post views function
- $count_key = 'views';
- $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);
- }
- }
- }
- set_transient( $key, $value, 60*60*24 );
- 192.160.0.5x333
- set_transient( $key, $value, 60*60*12 );
- function setPostViews($postID) {
- //check if user not administrator, if so execute code block within
- if( !current_user_can('administrator') ) {
- //all code goes here...
- }
- }
- function slzexploore_postview_set() {
- global $post;
- $post_types = array('post', 'slzexploore_tour', 'slzexploore_hotel');
- if( $post ) {
- $post_id = $post->ID;
- if( in_array(get_post_type(), $post_types) && is_single() ) {
- $count_key = 'slzexploore_postview_number';
- $count = get_post_meta( $post_id, $count_key, true );
- if( $count == '' ) {
- $count = 0;
- delete_post_meta( $post_id, $count_key );
- add_post_meta( $post_id, $count_key, '0' );
- } else {
- $count++;
- update_post_meta( $post_id, $count_key, $count );
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement