Hi i am new to wordpress i want to create a plugin which shows popular post. So i want to count the number of view of each post when it is loaded i have tried this but it always returns 0
add_action('template_redirect','lm_count_post');
function lm_count_post(){
$count_key = 'post_views_count';
$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++;
$x=update_post_meta($postID, $count_key, $count);
print_r();
}
echo $count; //die();
}
i am not sure whether the add_action function which i gave is right or not. Any one Please help me
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire