• Resolved s2am

    (@s2am)


    I’ve tried for hours all kinds of variations of this but it doesn’t work. I have up (+1) and down (-1) rating-options but it sorts them different than normal but not after the rating number.

    <?php query_posts( array( 'meta_key' => 'ratings_average', 'orderby' => 'meta_value_num', 'order' => 'DESC' ) ); ?>

    The strange thing is that sort after most rated works:
    <?php query_posts( array( 'meta_key' => 'ratings_users', 'orderby' => 'meta_value_num', 'order' => 'DESC' ) ); ?>

    Display highest rated works also:
    <?php get_highest_rated_category(9, 'both', 0, 10); ?>

    Even the URL Paramenter sorts them correctly:
    https://yoursite.com/?r_sortby=most_rated&r_orderby=desc

    Do you have an idea why sorting after highest rated doesn’t work?

    This is the complete code:

    <?php $args = array(
                'post_type' => 'post',
                'post_status' => 'publish',
                'cat' => '9',
                'posts_per_page' => 10,
    'meta_key' => 'ratings_average', 
    'orderby' => 'meta_value_num', 
    'order' => 'DESC',
            ); ?>
    
    <?php query_posts($args); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <?php get_template_part( 'content', get_post_format() ); ?>
    <?php endwhile; endif; ?>
    
    <?php wp_reset_query(); ?>

    =================

    I think the problem was that I confused
    %RATINGS_AVERAGE% – Display the average ratings
    with
    %RATINGS_SCORE% – Display the total score of the ratings

    • This topic was modified 5 years, 10 months ago by s2am. Reason: Found Problem
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Sort after Highest Rated – Doesn’t work’ is closed to new replies.