Assuming a post’s average rating is saved in the postmeta table somewhere, include the associated keyname as a “meta_key” argument, but do not supply a “meta_value” arg (unless you want to limit posts to those with that one value). Then for the “orderby” arg, specify “meta_value_num”, assuming the saved ratings are numeric.
If the ordering criteria does not exist in the DB and must be calculated on the fly, you could apply a custom sorting algorithm to the query’s posts property by using PHP’s usort() function.
https://www.php.net/manual/en/function.usort.php
Thank you very much! You helped a lot! 🙂
I used to use the usort() function, but for some reason I didn’t think of it now.
Thanks again! 😉