Show the most popular post per week
The plugin Most Popular Posts doesn't support WPML and therefore I have tried creating my own.
I have found this tutorial in creating your own code for showing the most popular posts on my site: How to Display Popular Posts by Views in WordPress without a Plugin
However this doesn't take in the factor of per week. I would like it to be pointed in the right direction on how to do this.
This code updates the posts actual view-count:
function wpb_set_post_views($postID) {
$count_key = 'wpb_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);
}
}
//To keep the count accurate, lets get rid of prefetching
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
Add these fields to the post:
week_count: integer
current_week: datetime
Check if current_week
matches the actual current week, otherwise reset the week_count
and add 1 and set the current_week
to the actual current week.
Is there another way of doing this in a smarter and more effiecient way?
Topic popular-posts multi-language php customization Wordpress statistics
Category Web