Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

WordPress does not include a built-in page-view counter for posts. To find your most-viewed posts without adding a plugin, use an analytics service you already have, use WordPress.com Stats if your site is hosted there, or build a custom counter that fits your site’s caching setup.

First choose where the view counts will come from

A WordPress post record can hold metadata, but WordPress’s standard post schema does not define a native view-count field or analytics system. The REST API’s posts collection lets you retrieve and query posts; it does not turn those records into view reports. See the WordPress REST API Posts reference.

Choose a source before building a popular-post list. Each source may define a view differently, so totals from separate systems are not necessarily comparable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Existing analytics service: Use its post-level reports if it already tracks page visits. This avoids creating a second counter, but reporting and definitions depend on that service.
  • WordPress.com Stats API: If your site and account have the relevant access, WordPress.com documents API endpoints for an individual post’s views and for per-post view totals. These are hosted-service statistics, not a feature guaranteed on every self-hosted WordPress installation. See WordPress.com Developer Resources.
  • Custom self-hosted counter: Store counts yourself when you need a counter tailored to your site. You must decide what counts as a view, where counts are stored, and how they are collected and displayed.

Plan for page caching before implementing a counter

A simple PHP counter can increment when WordPress renders a post at the origin. But if a full-page cache serves a saved response without running that PHP path, the request may not reach the counter. That can lead to undercounting.

Choose a counting route that matches your host, cache, traffic, and reporting needs. The WordPress metadata and REST documentation explains how to store and expose data; it does not prescribe a universal cache-safe counting method, bot policy, or performance threshold. Do not assume a request-time snippet will record every visit on every hosting setup.

Build a custom counter around a clear definition of “view”

For a self-hosted implementation, the basic pattern is to identify a singular published post request, get its post ID, record a view against that ID, and query the stored totals when building a ranking. The count may live in a dedicated post metadata key or a separate analytics store. This is custom tracking logic, not a built-in WordPress feature.

Decide what the counter measures

Before collecting data, set rules for repeat visits, bots, and retention. Also choose whether “popular” means lifetime views or views within a time window. These choices change the ranking, so label the result accordingly rather than presenting an undefined number as a universal measure of popularity.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Store and retrieve counts

If you use post metadata, WordPress provides get_post_meta() to retrieve metadata associated with a post. See the get_post_meta() function reference. Your implementation must still handle the update/increment operation and the collection of qualifying views; the function reference does not supply a complete counter.

Query and rank eligible posts

Once counts are stored consistently, retrieve eligible posts and order them by the count key to make a popular-post list. For example, a theme can render a list using WordPress functions directly; WordPress’s REST API is not required just to build a theme. See the REST API Handbook.

Make the ranking’s scope visible to readers: a lifetime list and a recent-period list answer different questions. If the implementation stores only one cumulative total, it cannot provide a time-window ranking without additional dated data or a separate analytics store.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Expose a custom count through the REST API only when needed

Storing a count as post metadata does not automatically make it appear in REST API responses. If another application needs to read it through the API, register the metadata with register_meta() or register_post_meta() and configure it for REST exposure. WordPress documents this requirement in Modifying Responses.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This is separate from counting: metadata registration controls whether the value is available in REST responses; it does not record views or calculate rankings.

Match the approach to the job

Approach Where counts come from Caching consideration REST access
Existing analytics service The service’s own visit reporting and definition Depends on how that service collects visits Depends on the service and integration
WordPress.com Stats API WordPress.com’s documented post-view statistics, subject to account/API access Not stated in the cited API reference Use the documented hosted-service API endpoints
Custom metadata counter Your own counting rules and WordPress post metadata Must be designed for the site’s cache; origin-only PHP may miss cached requests Register metadata if another application needs the field in REST responses

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.