• Hi guys,
    is there a way to show (for example in the category page) the average vote of all the reviews in that category?

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter andreilsero

    (@andreilsero)

    Nothing? 🙁

    Plugin Author MyThemeShop

    (@mythemeshop)

    Hello,

    You can try the following code to display the average author ratings:

    
    <?php
    
    $posts = get_posts( array(
      'category' = > 12,
      'meta_key' => 'wp_review_total',
      'fields' => 'ids',
    ) );
    $ratings = array();
    foreach ( $posts as $post ) {
      $ratings[] = get_post_meta( $post, 'wp_review_total', true );
    }
    
    echo 'Average is ' . ( array_sum( $ratings ) / count( $ratings ) );
    
    ?>
    

    Thank you.

    Thread Starter andreilsero

    (@andreilsero)

    Many thanks,
    and what do I have to change in this code if I want to display the average user ratings instead of the authors’?

    Plugin Author MyThemeShop

    (@mythemeshop)

    Hello,

    You can replace wp_review_total with wp_review_user_reviews.

    Thank you

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Average review in category’ is closed to new replies.