• WP Statistics shows 0 views on all pages in the main WP Dashboard Posts column.. and everywhere else that I have checked except for WPS’s Overview page. In WPS Overview page, it shows expected traffic, but Page Insights, Top Pages, etc show 0 views.

    Troubleshooting:

    I ran the debugger, found no issues.

    I’ve already completely reinstalled the plugin, using the delete everything option and it made no difference.

    Only other plugins installed are MailPoet (which was a recent install and didn’t affect this issue) and WP Popular Posts. I’ve seen no difference with WP Popular Posts disabled.

Viewing 1 replies (of 1 total)
  • Plugin Author Mostafa Soufi

    (@mostafas1990)

    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

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.