How to display wordpress posts sorted by post view count [Solved: without a plugin]

Several plugins are there which displays the posts according to number views( number of times the post is viewed). We can achieve the same thing without using a plugin. We can use this code in a particular WordPress theme files. Also it’s very easy to sort the posts according to the post views. Even, we can use the view count to display it side to each post.


  1. Paste the code below into your current theme’s function.php file. Try to use child theme if you are not already having one.(Child theme is optional though)
  2. Open single.php file which is responsible to display each post in WordPress and paste this single line of code inside the loop
  3. You can display the post view count by using this line of code inside the WordPress loop on any page.
  4. We can display posts sorted by Post view counts by using the code below.

WordPress plugins for post view counts are good but those provide extra functionalities which are not really needed for most of the cases; so why to bloat the setup and add to the response load of the website. Fastness of website matters !! 🙂