Hey guys, i have a wordpress theme and i use below code for page/post view (into function.php)
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return;
}
return $count;
}
// function to count views.
function setPostViews($postID) {
$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 ++;
update_post_meta($postID, $count_key, $count);
}
}
I want to adding 1 hour delay to update post view for example if post view is 0 don’t change it for 1 hour but saving that and after 1 hour update it to the last saved view and repeat this job.
How can i do it? Help me guys :