Just another contact form plugin. Simple but flexible.
About WP-PostViews
This document provides instructions on how to use the WP-PostViews plugin for WordPress. It explains where to place the code to display post views on your website and how to configure the plugin in the WordPress admin panel. It also includes information on the plugin's development, translations, credits, and recent updates.Screenshots


Frequently asked questions
How do I display post views on my WordPress site?
You can display post views by adding `<?php if(function_exists('the_views')) { the_views(); } ?>` to your theme files like `index.php`, `archive.php`, `single.php`, `post.php`, or `page.php`. Alternatively, use the shortcode `[views]` or `[views id="1"]` within a post.
Where can I configure the WP-PostViews plugin?
The plugin can be configured by navigating to WP-Admin -> Settings -> PostViews in your WordPress dashboard.
What are some of the template variables available in WP-PostViews?
Available template variables include `%POST_CATEGORY_ID%` (which returns the Post's Category ID, or priority Category ID with Yoast SEO) and `%POST_THUMBNAIL%`.
Does the plugin count views in preview mode?
No, the plugin is designed not to count views when a post is in preview mode.
Can I embed view counts directly into a post?
Yes, you can embed view counts into a post using the shortcode `[views]` or `[views id="POST_ID"]`.
Changelog
2.0.1
- NEW: A Settings link on the plugin’s row on the Plugins screen
- FIXED: “Count Views From” was only honoured while the page rendered. On a cached site the counting happens through a separate AJAX or REST call instead, and that path never asked the setting — so with “Registered Users Only” a guest hitting a cached page was still counted, and the bot exclusion never applied there either. Both endpoints now check the setting against the actual visitor’s login state
2.0.0
- FIXED: The two templates are echoed as markup on the strength of being
wp_kses_post()‘d when saved — and that was true only of the settings screen. The 2.0.0 migration writes through a different door, and the row it folds in comes from a release that stored the field with no filtering at all, so a hostile template on a site upgrading from 1.78.1 was carried across verbatim and echoed to every visitor. The filtering now happens where the row is written, so WP-CLI, cron, a restored backup and another plugin all pass through it too - FIXED: The deferred counting endpoint checked only that an ID named something, and every row in
wp_postsanswers to that — revisions, autosaves, auto-drafts, attachments, trashed posts, drafts, menu items, reusable blocks. An unauthenticated caller could walk the ID space writing a view row against each one, and read back the count of unpublished posts while doing it. It now requires a real, publicly viewable post, which is what the other counting path already knew - FIXED: A view count that is not a number — the meta key is unprefixed, so anyone who can edit a post can type one into Custom Fields — turned every listing containing that post into a fatal error on PHP 8, because both count tokens are built whether or not the template uses them
- NEW: An editor block, Post Views, under Widgets. It renders on the server through the same code the shortcode uses, so a block and a shortcode showing the same post produce the same markup, and previewing it in the editor never counts a view. The
[views]shortcode is unchanged and still supported — nothing needs converting, and posts already containing it keep working. - NEW: A
wp postviewsWP-CLI command —listandget. It reads and never writes. - NEW: A
postviews/v1REST API carrying one route, for counting a view from a cached page. Reading a count is already aviewsfield on the core post resource. Theadmin-ajax.phpwp_postviewsaction is unchanged and still supported. - BREAKING: Requires WordPress 6.8 and PHP 8.2.
- BREAKING: The
the_viewsfilter is nowwp_postviews_the_views. The template tagthe_views()is unchanged. - BREAKING: The
postviews_should_countfilter is nowwp_postviews_should_count. - BREAKING: The
postviews_increment_viewsandpostviews_increment_views_ajaxactions are nowwp_postviews_increment_viewsandwp_postviews_increment_views_ajax. - BREAKING: The settings are stored in
wp_postviews_optionsinstead ofviews_options, and the upgrade markers inwp_postviews_versioninstead ofviews_version. Both are migrated automatically. - BREAKING: The WP-Stats toggles move out of the shared
stats_displayandstats_mostlimitrows into this plugin’s own settings, and the shared rows are deleted. Update all seven WP-Stats plugins together. - BREAKING: The widget class
WP_Widget_PostViewsis nowWP_PostViews_Widget. Configured widgets are unaffected. - BREAKING: The AJAX action a cached page posts to is now
wp_postviewsinstead ofpostviews. - BREAKING: The six Display Options settings — home page, single posts, pages, archives, searches and other pages — are removed, and the stored keys are dropped on upgrade. Their replacement is the
wp_postviews_should_displayfilter. - NEW: Restructured into
includes/classes. The template tags —the_views(),get_most_viewed(),get_least_viewed(), and the category and tag variants — are unchanged and keep working exactly as before. - NEW: The options screen is rebuilt on the WordPress Settings API and no longer loads jQuery.
- NEW: The WP-Stats section, and how many entries its most viewed lists carry, are now settings on Settings -> WP-PostViews.
- NEW: The
wp_postviews_should_displayfilter decides whether a count is shown. It is read bythe_views()only; the[views]shortcode and the admin Views column are explicit requests and ignore it. - CHANGED: The settings screen is two tabs, Settings and Templates, over one settings group and one option row.
- CHANGED: The settings screen is titled “Post Views Settings”, matching the other settings screens in this family.
- CHANGED: WP-Stats now receives one Views section rather than three separately toggled panels, so the most viewed pages list appears alongside the posts list.
- FIXED:
%VIEW_COUNT_ROUNDED%picked its unit before rounding, so 999,950 displayed as “1000K” instead of “1M” and 999,999,999 as “1000M” instead of “1B”. - FIXED: Titles were truncated on bytes rather than characters, because the multibyte branch was gated on
MB_OVERLOAD_STRING, which PHP 8.0 removed. A CJK title cut mid-character disappeared from the most/least viewed lists entirely. - FIXED: The AJAX endpoint recorded views against post IDs that do not exist, letting anyone add rows to
wp_postmetaindefinitely. - FIXED:
?v_orderby=ASCwas compared against lowercase only, so an uppercase direction — which is what the FAQ tells you to use — silently fell back to descending, the opposite of what was asked for. - FIXED: The widget silently discarded changes made in the block widget editor and the customizer, because it required a hidden form field neither of them sends.
- FIXED: The widget warned about undefined array keys when rendered from the block widget editor or the customizer.
- FIXED: Uninstalling on a network of more than 100 sites left options and view counts behind on every site after the hundredth, and reported success. Network activation could fatal on the removed
wp_get_sites(). - NOTE: The settings screen moved from
options-general.php?page=wp-postviews/postviews-options.phptooptions-general.php?page=wp-postviews. Update any bookmark; the Settings -> WP-PostViews menu item is where it always was. - NOTE: Templates are now stored unslashed. Existing templates are migrated automatically the first time 2.0.0 loads.
- NOTE:
should_views_be_displayed(),postviews_round_number()andsnippet_text()are no longer global functions. They were never documented; they are nowWP_PostViews_Display::should_be_displayed(),WP_PostViews_Display::round_number()andWP_PostViews_Display::snippet_text().
