• Resolved steplab

    (@steplab)


    I have troubles tring to sort posts by rating.

    I tried to follow documentation, and previous topics but didn’t worked:

    
    $args = array('post_type' => 'mycustomposttype');
    if( $filter_by_rating ){
    $args['orderby'] = 'gdrts';
    $args['gdrts_method'] = 'stars-rating';
    $args['gdrts_value'] = 'rating';
    $args['gdrts_scope'] = 'all';
    }
    $posts = get_posts( $args );
    

    What is wrong?
    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Milan Petrovic

    (@gdragon)

    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.

    Thread Starter steplab

    (@steplab)

    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]

    Thread Starter steplab

    (@steplab)

    I added this argument to my get_posts:

    $args['suppress_filters'] = false;

    Maybe this was suppressing your filters?

    Thread Starter steplab

    (@steplab)

    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,
    ) );
    Plugin Author Milan Petrovic

    (@gdragon)

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Sorting by rating in get_posts’ is closed to new replies.