How to create algorithm for ordering posts in WordPress?


I have a news feed in my website where all the blog posts are displayed. WordPress default is to dislay these in order “latest first”. Using Elementor and Likebtn I have learned how to order the posts based on likes by creating a query ID “sort_by_likes” in Elementor Post Widget and inputting the code below in my functions.php file. But I want to use a more advanced algorithm for displaying my posts which weights in number of views, likes, date of publication and some randomization variable. How can I solve that?

add_action(‘elementor/query/sort_by_likes’, function($query){

$query->set('orderby', 'meta_value');
$query->set('meta_key', 'likes');   


, , , raen 2 years 2020-08-16T06:10:20-05:00 0 Answers 48 views 0

Leave an answer