The function getPostViews() is retrieving the total number of views for each post while setPostViews() increases the post views counter each time post is viewed.
You need to call setPostViews() somewhere in your single.php and then use below code to retrieve posts on basis of posts view count.
$args = Array(
'post_type' => 'post',
'posts_per_page' => '5',
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
$popular = new WP_Query( $args );
<?php while($popular->have_posts()) : $popular->the_post(); ?>
<?php the_post_thumbnail(); ?> <?php the_title(); ?> <?php the_content(); ?>
<?php endwhile ?>
Related Posts:
- Setting posts_per_page for taxonomy term template
- Send post id through ajax and get the post content back
- restrict incrementation of post vies count when refreshing the page
- How to detect single.php (but not single-portfolio.php)?
- How to get Images included in Post
- disable WP automatically inserted line breaks after an image
- Getting the post_id in wp_ajax function
- delete post also attachments
- How to call function within a page/post, to dynamically generate content?
- Restrict users from editing post based on the age of the post
- Writing a view count with w3 total cache
- List only child categories a post is in, of a specific parent category
- Add link on the top menu of the post table?
- Accessing $post variable from template part
- How to change post status from publish to draft using hook in wordpress?
- Guest Author – How to modify my custom function code if the guest author URL will follow a particular pattern/format?
- how to show all post in my page-grid.php template page
- Force update all posts in custom post type, no content changes
- Disable REST API for a user ROLE
- How to display post tags
- Add confirmation popup on “Move to Trash”
- Allow role to delete posts but block him the wp-admin
- How only display all post related to category
- Is it possible to have two different previews of a post (ie. two templates for one post)?
- How can I list random authors from current post category?
- Disable single post page
- Different template for posts of all subcategories of category
- Enabling post thumbnails for custom post type
- Custom Post Templates
- Templating of a specific post ID
- Getting current post ID in functions.php
- What part of template to edit to remove category name from the top of posts?
- Load post attached images on a single page site with fancybox
- API endpoint to get most-read and popular posts
- Change post order random through out the entire WordPress
- How to display the link (title) and thumbnail post?
- How to do set post permalinks using 6 digit random unique function?
- How to create new post content templates for my users?
- How do I stop the loop from repeating in my category template?
- posts not showing on index.php
- disable Tab post on nav-menus page (Admin)
- Every second post different class in blog view
- Tell WP to use a specific template file in posts
- How to make different custom post layouts?
- Get post meta retrieving wrong value
- The_excerpt() doesn’t parse – how to change that?
- How to only publish posts with image in it
- Why won’t pagination work?
- Is it possible to give the user the chance to select between two single template files to use in a post?
- Create a custom posts page
- Display a list of users who have viewed the post you are viewing
- Force a specific template as default
- Using system date format
- Un-highlight Blog Menu Item when Category Menu Item is Selected
- Same post appears in related Posts?
- Post Templates and Post ID’s
- How do I disable the “by author” hyperlink on posts?
- Trying to query all posts in category 4
- Output Buffer Issue with Single Post View
- Prevent 404 of Author pages without posts
- Help on conditional statement to accompany wp_insert_post function please?
- How to save template data into wp_post table (post_content column)
- get category in list of posts // shortcode for custom related posts
- shortcode // get posts by ids
- Related post not showing table of content
- Find most used words in post titles
- $post->post_content empty while all other properties are correct
- Why does my “Add New Post” page have an old post in it?
- How to show post views shortcode data for each post on Posts List Page?
- Set a post expiration and delete a post when expirate
- Replace Tag Keyword With Link Within Post Content
- Get post id outside loop : Notice: Trying to get property of non-object
- Trim excerpt to first paragraph
- Custom post type template not called
- Page 2 has no posts?
- im trying make a function to auto correct posts when i open the posts in the backoffice
- How to change number of posts shown on homepage vs other pages?
- Show only top 3 posts from 3 categories in order on home page
- My blog “page” used to show a list of posts, but now it’s just showing the page content?
- Custom template for different post types
- Adding The Post Template Dropdown to WP-Admin
- Posts page template: How can I edit the markup for this?
- How to get posts from network blog
- Get post title by Alphabet
- How can I create a menu items from meta box based on users input
- Which hooks are essential for post templates?
- 1 post, 2 templates
- How to use wp_editor(); in functions.php then retrieve content in the template
- Creating / Editing a post from within site template
- How *not* to show the last post on the latest posts list
- save_post not working
- wp trim function not working
- custom post type single page template not working
- WordPress “Posts Page” isn’t showing template dropdown
- Insert Shortcode exactly at the end of the content
- display last post modified date in genesis child themes
- Custom Post-Rename Function Does Not Function in WordPress 6.x
- Is there a block to print post link standalone in a block theme?
- Show Next/Previous without Link
- Filters do not work when there are multiple (one works)