I've been working on a clients WP site which is an updated version of a custom theme i done for them early last year.
In the header of the main page they want to display several different section which were 'Editors Pick', 'Latest post' and 'Most popular post'.
I had these all done and dusted until they've come back to me and asked for a change to the popular post section.
At first we were counting comments to display the most popular post but they decided it would be better to use views to work out the most popular.
After a bit of hunting i found this...
Functions.php
/***************************************************
/ POST VIEWS
/***************************************************/
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 "0 View";
}
return $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);
}
}
Header.php
<?php query_posts('meta_key=post_views_count&orderby=meta_value_num&order=DESC&showposts=1');?>
... call rest of loop as normal ...
This works brilliantly and displays the content of the most popular post by views.
Problem is now that the client has come back to me and requested that the post displayed should be the most popular post of the past 24hours... and that's where i'm stuck.
Anyone have any idea how to modify what i've got? Is there anyway to hook into WP cron to flush the post views count at a certain time every 24 hours? Arghghgh any help will be most appreciated.
Cheers guys.
Mike
Help


















