This should be OK. How do you determined that it didn’t work? Also, maybe some other code is changing the query arguments before running.
Because posts always return in same order (date desc; new posts first)
I have 5 posts: 3 posts with 5 score, 2 posts with 3 score.
By post date I get:
[record-5-rate5]
[record-4-rate5]
[record-3-rate3]
[record-2-rate3]
[record-1-rate5]
Ordering by rating I espect to get:
[record-5-rate5]
[record-4-rate5]
[record-1-rate5]
[record-3-rate3]
[record-2-rate3]
But I get same as date order:
[record-5-rate5]
[record-4-rate5]
[record-3-rate3]
[record-2-rate3]
[record-1-rate5]
I added this argument to my get_posts:
$args['suppress_filters'] = false;
Maybe this was suppressing your filters?
I confirm adding the attribute ‘suppress_filters’ get_posts into false, that is default setted to true, your plugin filters will work.
WordPress get_posts
Maybe you can force to set this attribute with your class gdrts_addon_posts_sorter.
If someone have same issue simple example:
$posts = get_posts( array(
'orderby' => 'gdrts',
'gdrts_method' => 'stars-rating',
'gdrts_value' => 'rating',
'gdrts_scope' => 'all',
'suppress_filters' => false,
) );
I have made all examples for WP_Query, and get_posts() is setting filter suppression to true. I will updated knowledge base to include that.