Closed 84pixels closed 9 years ago
Sorry that is not possible. The plugin only stored accumulated views. It doesn't know each day you get how many hits. This is by design and I have no intention of changing it.
I have made function run with our extention.
Shorcode :
top_views(array(
'range' => 'week',
'limit' => '5'
))
Function :
function top_views($args) {
global $wpdb;
$where = "";
$prefix = $wpdb->prefix;
$now = current_time('mysql');
switch($args['range']){
case "today":
$where .= " AND p.post_date > DATE_SUB('{$now}', INTERVAL 1 DAY) ";
break;
case "week":
$where .= " AND p.post_date > DATE_SUB('{$now}', INTERVAL 1 WEEK) ";
break;
case "month":
$where .= " AND p.post_date > DATE_SUB('{$now}', INTERVAL 1 MONTH) ";
break;
default:
$where .= "";
break;
}
$limit = "LIMIT {$args['limit']}";
$query = "SELECT * FROM {$wpdb->posts} AS p,{$wpdb->postmeta} AS pm WHERE pm.meta_key = 'views' AND p.ID = pm.post_id {$where}ORDER BY pm.meta_value * 1 DESC {$limit}";
$trans_prefix = $args['range'] . '_' . $args['limit'] . 'top_10';
if ( false === ( $results = get_transient($trans_prefix) ) ) {
$results = $wpdb->get_results($query);
set_transient($trans_prefix, $results, 12 * HOUR_IN_SECONDS );
}
return $results;
}
That will only show views of posts that is posted within that time range and not the views that is accumulated within the time range.
Hello,
I use your extension long time. But I would like to extend it .
I want show post by views with interval of time day/week/month.
I have found ressource like this (http://wordpress.org/extend/plugins/wordpress-popular-posts) :
Someone can help me?