{"id":250,"date":"2006-02-08T22:30:16","date_gmt":"2006-02-08T22:30:16","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/wp-postviews\/"},"modified":"2025-08-31T05:28:43","modified_gmt":"2025-08-31T05:28:43","slug":"wp-postviews","status":"publish","type":"plugin","link":"https:\/\/mn.wordpress.org\/plugins\/wp-postviews\/","author":259,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"1.78","stable_tag":"1.78","tested":"6.8.5","requires":"4.0","requires_php":"","requires_plugins":null,"header_name":"WP-PostViews","header_author":"Lester 'GaMerZ' Chan","header_description":"","assets_banners_color":"e9eaec","last_updated":"2025-08-31 05:28:43","external_support_url":"","external_repository_url":"","donate_link":"https:\/\/lesterchan.net\/site\/donation\/","header_plugin_uri":"https:\/\/lesterchan.net\/portfolio\/programming\/php\/","header_author_uri":"https:\/\/lesterchan.net","rating":4.4,"author_block_rating":0,"active_installs":100000,"downloads":3385939,"num_ratings":65,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","faq","changelog"],"tags":{"1.00":{"tag":"1.00","author":"GamerZ","date":"2007-03-17 07:20:19"},"1.00beta":{"tag":"1.00beta","author":"GamerZ","date":"2007-03-17 07:20:19"},"1.01":{"tag":"1.01","author":"GamerZ","date":"2007-03-17 07:20:19"},"1.02":{"tag":"1.02","author":"GamerZ","date":"2007-03-17 07:20:19"},"1.10":{"tag":"1.10","author":"GamerZ","date":"2007-03-17 07:20:19"},"1.11":{"tag":"1.11","author":"GamerZ","date":"2007-06-19 17:31:53"},"1.20":{"tag":"1.20","author":"GamerZ","date":"2007-09-30 08:17:28"},"1.30":{"tag":"1.30","author":"GamerZ","date":"2008-06-10 07:36:46"},"1.31":{"tag":"1.31","author":"GamerZ","date":"2008-07-15 14:45:22"},"1.40":{"tag":"1.40","author":"GamerZ","date":"2009-02-07 13:57:06"},"1.50":{"tag":"1.50","author":"GamerZ","date":"2009-06-13 14:19:52"},"1.66":{"tag":"1.66","author":"GamerZ","date":"2014-03-04 00:49:09"},"1.67":{"tag":"1.67","author":"GamerZ","date":"2014-04-17 00:51:50"},"1.68":{"tag":"1.68","author":"GamerZ","date":"2014-09-07 07:10:37"},"1.69":{"tag":"1.69","author":"GamerZ","date":"2014-12-18 03:22:59"},"1.70":{"tag":"1.70","author":"GamerZ","date":"2015-04-21 13:56:10"},"1.71":{"tag":"1.71","author":"GamerZ","date":"2015-08-08 13:09:33"},"1.72":{"tag":"1.72","author":"GamerZ","date":"2015-11-23 02:45:54"},"1.73":{"tag":"1.73","author":"GamerZ","date":"2016-04-14 06:02:53"},"1.74":{"tag":"1.74","author":"GamerZ","date":"2016-12-08 03:27:58"},"1.75":{"tag":"1.75","author":"GamerZ","date":"2017-04-24 02:52:29"},"1.76":{"tag":"1.76","author":"GamerZ","date":"2018-12-19 04:52:22"},"1.76.1":{"tag":"1.76.1","author":"GamerZ","date":"2022-02-05 06:22:34"},"1.77":{"tag":"1.77","author":"GamerZ","date":"2023-08-09 03:05:44"},"1.78":{"tag":"1.78","author":"GamerZ","date":"2025-08-31 05:28:43"}},"upgrade_notice":{"":"<p>N\/A<\/p>"},"ratings":{"1":7,"2":1,"3":1,"4":8,"5":48},"assets_icons":{"icon.svg":{"filename":"icon.svg","revision":978002,"resolution":false,"location":"assets","locale":false}},"assets_banners":{"banner-1544x500.jpg":{"filename":"banner-1544x500.jpg","revision":1206762,"resolution":"1544x500","location":"assets","locale":""},"banner-772x250.jpg":{"filename":"banner-772x250.jpg","revision":1206762,"resolution":"772x250","location":"assets","locale":""}},"assets_blueprints":{},"all_blocks":[],"tagged_versions":["1.00","1.00beta","1.01","1.02","1.10","1.11","1.20","1.30","1.31","1.40","1.50","1.66","1.67","1.68","1.69","1.70","1.71","1.72","1.73","1.74","1.75","1.76","1.76.1","1.77","1.78"],"block_files":[],"assets_screenshots":{"screenshot-1.png":{"filename":"screenshot-1.png","revision":1206762,"resolution":"1","location":"assets","locale":""},"screenshot-2.png":{"filename":"screenshot-2.png","revision":1206762,"resolution":"2","location":"assets","locale":""}},"screenshots":{"1":"PostViews","2":"Admin - PostViews Options"},"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[869,5897,5899,872],"plugin_category":[36],"plugin_contributors":[77620],"plugin_business_model":[],"class_list":["post-250","plugin","type-plugin","status-publish","hentry","plugin_tags-counter","plugin_tags-hits","plugin_tags-postviews","plugin_tags-views","plugin_category-analytics","plugin_contributors-gamerz","plugin_committers-gamerz"],"banners":{"banner":"https:\/\/ps.w.org\/wp-postviews\/assets\/banner-772x250.jpg?rev=1206762","banner_2x":"https:\/\/ps.w.org\/wp-postviews\/assets\/banner-1544x500.jpg?rev=1206762","banner_rtl":false,"banner_2x_rtl":false},"icons":{"svg":"https:\/\/ps.w.org\/wp-postviews\/assets\/icon.svg?rev=978002","icon":"https:\/\/ps.w.org\/wp-postviews\/assets\/icon.svg?rev=978002","icon_2x":false,"generated":false},"screenshots":[{"src":"https:\/\/ps.w.org\/wp-postviews\/assets\/screenshot-1.png?rev=1206762","caption":"PostViews"},{"src":"https:\/\/ps.w.org\/wp-postviews\/assets\/screenshot-2.png?rev=1206762","caption":"Admin - PostViews Options"}],"raw_content":"<!--section=description-->\n<h3>Usage<\/h3>\n\n<ol>\n<li>Open <code>wp-content\/themes\/&lt;YOUR THEME NAME&gt;\/index.php<\/code><\/li>\n<li>You may place it in archive.php, single.php, post.php or page.php also.<\/li>\n<li>Find: <code>&lt;?php while (have_posts()) : the_post(); ?&gt;<\/code><\/li>\n<li>Add Anywhere Below It (The Place You Want The Views To Show): <code>&lt;?php if(function_exists('the_views')) { the_views(); } ?&gt;<\/code><\/li>\n<li>Or you can use the shortcode <code>[views]<\/code> or <code>[views id=\"1\"]<\/code> (where 1 is the post ID) in a post<\/li>\n<li>Go to <code>WP-Admin -&gt; Settings -&gt; PostViews<\/code> to configure the plugin.<\/li>\n<\/ol>\n\n<h3>Development<\/h3>\n\n<p><a href=\"https:\/\/github.com\/lesterchan\/wp-postviews\/\" title=\"https:\/\/github.com\/lesterchan\/wp-postviews\/\">https:\/\/github.com\/lesterchan\/wp-postviews\/<\/a><\/p>\n\n<h3>Translations<\/h3>\n\n<p><a href=\"http:\/\/dev.wp-plugins.org\/browser\/wp-postviews\/i18n\/\" title=\"http:\/\/dev.wp-plugins.org\/browser\/wp-postviews\/i18n\/\">http:\/\/dev.wp-plugins.org\/browser\/wp-postviews\/i18n\/<\/a><\/p>\n\n<h3>Credits<\/h3>\n\n<ul>\n<li>Plugin icon by <a href=\"http:\/\/www.icomoon.io\">Iconmoon<\/a> from <a href=\"http:\/\/www.flaticon.com\">Flaticon<\/a><\/li>\n<\/ul>\n\n<h3>Donations<\/h3>\n\n<p>I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.<\/p>\n\n<h3>Version 1.76.1<\/h3>\n\n<ul>\n<li>NEW: Add Post Author in views template<\/li>\n<li>NEW: Bump for WordPress 5.3<\/li>\n<\/ul>\n\n<h3>Version 1.76<\/h3>\n\n<ul>\n<li>NEW: Added postviews_should_count filter<\/li>\n<li>FIXED: Change to (int) from intval() and use sanitize_key() with it.<\/li>\n<\/ul>\n\n<h3>Version 1.75<\/h3>\n\n<ul>\n<li>NEW: Use WP_Query() for most\/least viewed posts<\/li>\n<\/ul>\n\n<h3>Version 1.74<\/h3>\n\n<ul>\n<li>NEW: Bump WordPress 4.7<\/li>\n<li>NEW: Template variable %POST_CATEGORY_ID%. It returns Post's Category ID. If you are using Yoast SEO Plugin, it will return the priority Category ID. Props @FunFrog-BY<\/li>\n<\/ul>\n\n<h3>Version 1.73<\/h3>\n\n<ul>\n<li>FIXED: In preview mode, don't count views<\/li>\n<\/ul>\n\n<h3>Version 1.72<\/h3>\n\n<ul>\n<li>NEW: Add %POST_THUMBNAIL% to template variables<\/li>\n<\/ul>\n\n<h3>Version 1.71<\/h3>\n\n<ul>\n<li>FIXED: Notices in Widget Constructor for WordPress 4.3<\/li>\n<\/ul>\n\n<h3>Version 1.70<\/h3>\n\n<ul>\n<li>FIXED: Integration with WP-Stats<\/li>\n<\/ul>\n\n<h3>Version 1.69<\/h3>\n\n<ul>\n<li>NEW: Shortcode <code>[views]<\/code> or [views id=\"POST_ID\"]` to embed view count into post<\/li>\n<li>NEW: Added template variable <code>%VIEW_COUNT_ROUNDED%<\/code> to support rounded view count like 10.1k or 11.2M<\/li>\n<\/ul>\n\n<h3>Version 1.68<\/h3>\n\n<ul>\n<li>NEW: Added action hook 'postviews_increment_views' and 'postviews_increment_views_ajax'<\/li>\n<li>NEW: Allow custom post type to be chosen under the widget<\/li>\n<\/ul>\n\n<h3>Version 1.67<\/h3>\n\n<ul>\n<li>NEW: Allow user to not use AJAX to update the views even though WP_CACHE is true<\/li>\n<\/ul>\n\n<h3>Version 1.66<\/h3>\n\n<ul>\n<li>NEW: Supports MultiSite Network Activation<\/li>\n<li>NEW: Add %POST_DATE% and %POST_TIME% to template variables<\/li>\n<li>NEW: Add China isearch engines bots<\/li>\n<li>NEW: Ability to pass in an array of post types for get_most\/least_*() functions. Props Leo Plaw.<\/li>\n<li>FIXED: Moved uninstall to uninstall.php and hence fix missing nonce. Props Julio Potier.<\/li>\n<li>FIXED: Notices and better way to get views from meta. Props daankortenbach.<\/li>\n<li>FIXED: No longer needing add_post_meta() if update_post_meta() fails.<\/li>\n<\/ul>\n\n<h3>Version 1.65 (02-06-2013)<\/h3>\n\n<ul>\n<li>FIXED: Views not showing in WP-Admin if \"Display Options\" is not set to \"Display to everyone\"<\/li>\n<\/ul>\n\n<!--section=faq-->\n<dl>\n<dt id=\"how%20to%20view%20stats%20with%20widgets%3F\"><h3>How To View Stats With Widgets?<\/h3><\/dt>\n<dd><ul>\n<li>Go to <code>WP-Admin -&gt; Appearance -&gt; Widgets<\/code><\/li>\n<li>The widget name is Views.<\/li>\n<\/ul><\/dd>\n<dt id=\"to%20display%20least%20viewed%20posts\"><h3>To Display Least Viewed Posts<\/h3><\/dt>\n<dd><pre><code>&lt;?php if (function_exists('get_least_viewed')): ?&gt;\n    &lt;ul&gt;\n        &lt;?php get_least_viewed(); ?&gt;\n    &lt;\/ul&gt;\n&lt;?php endif; ?&gt;\n<\/code><\/pre>\n\n<ul>\n<li>The first value you pass in is the post type that you want. If you want to get every post types, just use 'both'. It also supports PHP array: example <code>array('post', 'page')<\/code>.<\/li>\n<li>The second value you pass in is the maximum number of post you want to get.<\/li>\n<li>Default: get_least_viewed('both', 10);<\/li>\n<\/ul><\/dd>\n<dt id=\"to%20display%20most%20viewed%20posts\"><h3>To Display Most Viewed Posts<\/h3><\/dt>\n<dd><pre><code>&lt;?php if (function_exists('get_most_viewed')): ?&gt;\n    &lt;ul&gt;\n        &lt;?php get_most_viewed(); ?&gt;\n    &lt;\/ul&gt;\n&lt;?php endif; ?&gt;\n<\/code><\/pre>\n\n<ul>\n<li>The first value you pass in is the post type that you want. If you want to get every post types, just use 'both'. It also supports PHP array: example <code>array('post', 'page')<\/code>.<\/li>\n<li>The second value you pass in is the maximum number of post you want to get.<\/li>\n<li>Default: get_most_viewed('both', 10);<\/li>\n<\/ul><\/dd>\n<dt id=\"to%20display%20least%20viewed%20posts%20by%20tag\"><h3>To Display Least Viewed Posts By Tag<\/h3><\/dt>\n<dd><pre><code>&lt;?php if (function_exists('get_least_viewed_tag')): ?&gt;\n    &lt;ul&gt;\n        &lt;?php get_least_viewed_tag(); ?&gt;\n    &lt;\/ul&gt;\n&lt;?php endif; ?&gt;\n<\/code><\/pre>\n\n<ul>\n<li>The first value you pass in is the tag id.<\/li>\n<li>The second value you pass in is the post type that you want. If you want to get every post types, just use 'both'. It also supports PHP array: example <code>array('post', 'page')<\/code>.<\/li>\n<li>The third value you pass in is the maximum number of post you want to get.<\/li>\n<li>Default: get_least_viewed_tag(1, 'both', 10);<\/li>\n<\/ul><\/dd>\n<dt id=\"to%20display%20most%20viewed%20posts%20by%20tag\"><h3>To Display Most Viewed Posts By Tag<\/h3><\/dt>\n<dd><pre><code>&lt;?php if (function_exists('get_most_viewed_tag')): ?&gt;\n    &lt;ul&gt;\n        &lt;?php get_most_viewed_tag(); ?&gt;\n    &lt;\/ul&gt;\n&lt;?php endif; ?&gt;\n<\/code><\/pre>\n\n<ul>\n<li>The first value you pass in is the tag id.<\/li>\n<li>The second value you pass in is the post type that you want. If you want to get every post types, just use 'both'. It also supports PHP array: example <code>array('post', 'page')<\/code>.<\/li>\n<li>The third value you pass in is the maximum number of post you want to get.<\/li>\n<li>Default: get_most_viewed_tag(1, 'both', 10);<\/li>\n<\/ul><\/dd>\n<dt id=\"to%20display%20least%20viewed%20posts%20for%20a%20category\"><h3>To Display Least Viewed Posts For A Category<\/h3><\/dt>\n<dd><pre><code>&lt;?php if (function_exists('get_least_viewed_category')): ?&gt;\n    &lt;ul&gt;\n        &lt;?php get_least_viewed_category(); ?&gt;\n    &lt;\/ul&gt;\n&lt;?php endif; ?&gt;\n<\/code><\/pre>\n\n<ul>\n<li>The first value you pass in is the category id.<\/li>\n<li>The second value you pass in is the post type that you want. If you want to get every post types, just use 'both'. It also supports PHP array: example <code>array('post', 'page')<\/code>.<\/li>\n<li>The third value you pass in is the maximum number of post you want to get.<\/li>\n<li>Default: get_least_viewed_category(1, 'both', 10);<\/li>\n<\/ul><\/dd>\n<dt id=\"to%20display%20most%20viewed%20posts%20for%20a%20category\"><h3>To Display Most Viewed Posts For A Category<\/h3><\/dt>\n<dd><pre><code>&lt;?php if (function_exists('get_most_viewed_category')): ?&gt;\n    &lt;ul&gt;\n        &lt;?php get_most_viewed_category(); ?&gt;\n    &lt;\/ul&gt;\n&lt;?php endif; ?&gt;\n<\/code><\/pre>\n\n<ul>\n<li>The first value you pass in is the category id.<\/li>\n<li>The second value you pass in is the post type that you want. If you want to get every post types, just use 'both'. It also supports PHP array: example <code>array('post', 'page')<\/code>.<\/li>\n<li>The third value you pass in is the maximum number of post you want to get.<\/li>\n<li>Default: get_most_viewed_category(1, 'both', 10);<\/li>\n<\/ul><\/dd>\n<dt id=\"to%20sort%20most%2Fleast%20viewed%20posts\"><h3>To Sort Most\/Least Viewed Posts<\/h3><\/dt>\n<dd><ul>\n<li>You can use: <code>&lt;?php query_posts( array( 'meta_key' =&gt; 'views', 'orderby' =&gt; 'meta_value_num', 'order' =&gt; 'DESC' ) ); ?&gt;<\/code><\/li>\n<li>Or pass in the variables to the URL: <code>http:\/\/yoursite.com\/?v_sortby=views&amp;v_orderby=desc<\/code><\/li>\n<li>You can replace DESC  with ASC if you want the least viewed posts.<\/li>\n<\/ul><\/dd>\n<dt id=\"to%20display%20updating%20view%20count%20with%20litespeed%20cache\"><h3>To Display Updating View Count With LiteSpeed Cache<\/h3><\/dt>\n<dd><p>Use: <code>&lt;div id=\"postviews_lscwp\"&gt;&lt;\/div&gt;<\/code> to replace <code>&lt;?php if(function_exists('the_views')) { the_views(); } ?&gt;<\/code>.\nNOTE: The id can be changed, but the div id and the ajax function must match.\nReplace the ajax query in <code>wp-content\/plugins\/wp-postviews\/postviews-cache.js<\/code> with<\/p>\n\n<pre><code>jQuery.ajax({\n    type:\"GET\",\n    url:viewsCacheL10n.admin_ajax_url,\n    data:\"postviews_id=\"+viewsCacheL10n.post_id+\"&amp;action=postviews\",\n    cache:!1,\n    success:function(data) {\n        if(data) {\n            jQuery('#postviews_lscwp').html(data+' views');\n        }\n   }\n});\n<\/code><\/pre>\n\n<p>Purge the cache to use the updated pages.<\/p><\/dd>\n<dt id=\"to%20get%20views%20with%20rest%20api\"><h3>To Get Views With REST API<\/h3><\/dt>\n<dd><p>You can obtain the number of post views by adding <code>views<\/code> to your <code>_fields<\/code> parameter:\n    \/wp\/v2\/posts?_fields=views,title<\/p><\/dd>\n\n<\/dl>\n\n<!--section=changelog-->\n<h3>Version 1.78<\/h3>\n\n<ul>\n<li>NEW: Add %POST_THUMBNAIL_URL% to template variables<\/li>\n<\/ul>\n\n<h3>Version 1.77<\/h3>\n\n<ul>\n<li>NEW: Use Vanilla JS. Props @JiveDig<\/li>\n<li>NEW: Bump to WordPress 6.2<\/li>\n<li>NEW: Support views under fields for Rest API. Props @vitro-mod<\/li>\n<\/ul>","raw_excerpt":"Enables you to display how many times a post\/page had been viewed.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mn.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mn.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/mn.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/mn.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=250"}],"author":[{"embeddable":true,"href":"https:\/\/mn.wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/gamerz"}],"wp:attachment":[{"href":"https:\/\/mn.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=250"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/mn.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=250"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/mn.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=250"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/mn.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=250"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/mn.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=250"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/mn.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}