Hi there,
Thanks for reporting this. The Views column uses calculateHitCount() in HitColumnHandler.php (line 283). Several things can cause it to show 0. Let’s add simple debug logging to each step so you can find exactly where it breaks.
Step 1: Add debug lines
Open this file: wp-content/plugins/wp-statistics/src/Service/Admin/Posts/HitColumnHandler.php Find the calculateHitCount method (line 283) and add error_log lines like this:
private function calculateHitCount($objectId, $term = null)
{
error_log("[WPS Debug] === calculateHitCount START for ID: $objectId ===");
// Don't calculate stats if count_display is disabled
error_log("[WPS Debug] count_display: " . $this->miniChartHelper->getCountDisplay());
if ($this->miniChartHelper->getCountDisplay() === 'disabled') {
error_log("[WPS Debug] STOPPED: count_display is disabled, returning null");
return null;
}
$hitArgs = [
'resource_type' => $this->getCache('postType'),
'ignore_date' => true
];
error_log("[WPS Debug] resource_type: " . $this->getCache('postType'));
// Change resource_type parameter if it's a term
if (!empty($term)) {
$hitArgs['resource_type'] = $this->getCache('postType');
}
if ($this->miniChartHelper->getCountDisplay() === 'date_range') {
$hitArgs['date'] = [
'from' => TimeZone::getTimeAgo(intval(Option::getByAddon('date_range', 'mini_chart', '14'))),
'to' => date('Y-m-d'),
];
error_log("[WPS Debug] date_range mode, from: " . $hitArgs['date']['from'] . " to: " . $hitArgs['date']['to']);
}
// Cache hitArgs
$this->setCache('hitArgs', $hitArgs);
$hitCount = 0;
error_log("[WPS Debug] chart_metric: " . $this->miniChartHelper->getChartMetric());
if ($this->miniChartHelper->getChartMetric() === 'visitors') {
$visitorsModel = new VisitorsModel();
$hitCount = $visitorsModel->countVisitors(array_merge($hitArgs, ['resource_id' => $objectId]));
error_log("[WPS Debug] visitors hitCount: $hitCount");
} else {
$viewsModel = new ViewsModel();
$hitCount = $viewsModel->countViewsFromPagesOnly(array_merge($hitArgs, ['post_id' => $objectId]));
error_log("[WPS Debug] views hitCount (before historical): $hitCount");
// Consider historical if count_display is equal to 'total'
if ($this->miniChartHelper->getCountDisplay() === 'total') {
$uri = empty($term) ? get_permalink($objectId) : get_term_link(intval($term->term_id), $term->taxonomy);
$uri = !is_wp_error($uri) ? wp_make_link_relative($uri) : '';
error_log("[WPS Debug] historical URI: $uri");
$hitCount = $viewsModel->countViewsFromPagesOnly(array_merge($hitArgs, ['post_id' => $objectId, 'uri' => $uri, 'historical' => true]));
error_log("[WPS Debug] views hitCount (with historical): $hitCount");
}
}
error_log("[WPS Debug] === FINAL hitCount for ID $objectId: $hitCount ===");
return $hitCount;
}
Step 2: Check the log
Go to Posts → All Posts in your admin, then check your wp-content/debug.log file (make sure WP_DEBUG and WP_DEBUG_LOG are enabled in wp-config.php).
Look for the [WPS Debug] lines. The output will tell you exactly:
- Is
count_display set to disabled? (That would stop everything)
- What
resource_type is being used? (Should be post for posts)
- Is it using
views or visitors metric?
- What’s the count before and after historical data?
- What URI is being used for historical lookup?
Best