I'm making a drawing website using WordPress and allowing my users to draw and post their drawings as pinned posts
Now I want to make the theme I'm using to change the order of the displayed posts to be displayed by number of views or comments not by the date order
Where can I find the code responsible for the posts displaying order in the theme of WordPress.
To order post by comment count
To order post by view
By default WordPress does not have any option to short post by view so you have to use a little trick
Now that we have set our logic for view so we 'll be shorting it
To order post by both view and comment count
If you want to
orderby
both the score then again we have to apply a small trick, as there is no default option in WordPress. First we'll count the comment and we'll add a small weightage and add the total view count and keep it is a different meta field and then we'll sort the post on that key.Please Note : Adding extra weight to comment is not mandatory, but if reader will realy like the post then only they 'll give the comment.
Code goes in function.php file of your active child theme (or theme). Or also in any plugin php files.
Code is tested and works.
Hope this helps!