WordPress Tips: Display most viewed posts first on search pages
WordPress by default, shows latest posts first on archive and search pages. Here I will show you how tosort your posts on search results page using post view counts.
Step 1. Install Lester Chan’s post views plugin.
This plugin counts every time a visitor views a single post page. Go to Plugins > Add New > Search
and type wp postviews for easy install.
Step 2. Open functions.php
and add the code below to the end of the file right before ?>
(if there is one).
This code filters your posts when a visitor views your search page. It sorts results by post view counts. Your most visited posts will be on top.
Step 3. Save & upload the file to your server.
If you just installed the wp-postviews plugin, it may take some time for this trick to work.
Source shailan.com