Receive page’s visits number in different periods of time

You can receive the number of visits from a page or post in different periods of time. It’s done with the following PHP code:

$page_id = 3; // Your page ID

// Get page hits
$today = wp_statistics_pages('today', $page_id);
$yesterday = wp_statistics_pages('yesterday', $page_id);
$week = wp_statistics_pages('week', $page_id);
$month = wp_statistics_pages('month', $page_id);
$year = wp_statistics_pages('year', $page_id);
$total = wp_statistics_pages('total', $page_id);
$range = wp_statistics_pages('-10', $page_id); // For the past 10 days

Leave Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.