Last active
December 17, 2015 20:29
-
-
Save UmeshSingla/5668126 to your computer and use it in GitHub Desktop.
Wordpress Popular Post(No. of Post Views)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Add this code to function.php file */ | |
/* Post View Increment */ | |
function rtp_popular_post(){ | |
global $post; | |
$count_key = '_rtp_post_view_count'; | |
if(is_single()){ | |
$view_count = get_post_meta($post->ID, $count_key, true); | |
if($view_count==''){ | |
$view_count = 0; | |
//Delete all custom fields with the specified key from the specified post. | |
delete_post_meta($post->ID, $count_key); | |
//Add a custom (meta) field (Name/value)to the specified post. | |
add_post_meta($post->ID, $count_key, '0'); | |
} | |
else | |
$view_count++; | |
update_post_meta($post->ID, $count_key, $view_count); | |
} | |
} | |
add_action('wp','rtp_popular_post'); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment