• Resolved barkntuncer

    (@barkntuncer)


    Dear users/moderators,

    I am trying to rank the reviews based on their stars given. I have read the FAQ however when I try to paste this code;

    $query = new WP_Query([
        'meta_query' => [
            'relation' => 'OR',
            ['key' => '_glsr_ranking', 'compare' => 'NOT EXISTS'], // this comes first!
            ['key' => '_glsr_ranking', 'compare' => 'EXISTS'],
        ],
        'order' => 'DESC',
        'orderby' => 'meta_value_num',
        'post_status' => 'publish',
        'post_type' => 'page', // change this as needed
        'posts_per_page' => 10, // change this as needed
    ]);
    
    if ($query->have_posts()) {
        while ($query->have_posts()) {
            $query->the_post();
            $average = sprintf('%s (average rating: %s)',
                get_the_title(),
                get_post_meta($post->ID, '_glsr_average', true)
            );
            $ranking = sprintf('%s (ranking: %s)',
                get_the_title(),
                get_post_meta($post->ID, '_glsr_ranking', true)
            );
            apply_filters('glsr_debug', 'Site Reviews is not installed', $average, $ranking);
        }
        wp_reset_postdata();
    }

    to the Customization –> Theme editor –> index.php, nothing happens. I am using Astra as my theme. Most probably I am writing this code to the wrong place. I could not find a suitable place. Can you help me?

    Best regards,
    Barkin

    • This topic was modified 4 years, 3 months ago by barkntuncer.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    Ranking is used to sort pages that have reviews assigned to them. It is not used to sort reviews.

    The snippet example in the documentation is a PHP snippet which shows how to use the ranking meta key that is given to pages which have reviews assigned to them in a custom WordPress query.

    Plugin Author Gemini Labs

    (@geminilabs)

    Site Reviews sorts reviews by latest to oldest. It allows you to pin your best reviews to the top, and allows you to restrict reviews that are displayed to a minimum rating (i.e. only show reviews that are rated 3 stars or higher).

    If you need more advanced controls, such as being able to filter, search, and sort reviews, please see the Review Filters add-on.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Cannot rank the revies by their stars’ is closed to new replies.