WordPress.org

Ready to get started?Download WordPress

Forums

WP Customer Reviews
Inserting Average Review on another Page (7 posts)

  1. kaylamatthews
    Member
    Posted 1 year ago #

    Following this thread:

    http://wordpress.org/support/topic/plugin-wp-customer-reviews-average-review-desperately-needed

    I was able to create the average score on the post/page where the review is enabled.

    I am currently using the shortcode [WPCR_SHOW] to show the rating on another page, however am having a really hard time showing the average rating on that page.

    I know the modifications need to be made inside the

    function output_reviews_show()

    function inside wp-customer-reviews.php but am not sure how to do it. I have used the same code as found in the above thread but the average review is always ZERO since it's capturing the aggregate review for the page where the shortcode is embedded.

    Let's look at the code in the thread above that is pulling the average rating for the post where the review form is embedded:

    The function:

    function get_average_rating() {
             global $post;
             $this->get_aggregate_reviews($post->ID);
             $average_score = number_format($this->got_aggregate["aggregate"], 1);
    
            return $average_score * 20; // 20% for each star if having 5 stars
        }

    HTML rendering:

    $average_rating = 'Average Rating: <div class="sp_rating"><div class="base"><div class="average" style="width:'.$this->get_average_rating().'%"></div></div></div>';

    Inserting average rating into the template:

    $the_content .= $average_rating;

    The issue I believe is the ($post->ID) array inside the average_rating function as it's telling the average_rating function to grab the aggregate value for the page the shortcode is embedded on. I have tried so many things I don't know where to begin to post here, I am not a PHP expert unfortunately.

    Rending the HTML and calling it in the template via

    $reviews_content = $average_rating; inside the

    function output_reviews_show section

    is straightforward but I do not know how to make it so the average rating in this case is based on the postid the [WPCR_SHOW] shortcode indicated.

    Does anybody have any ideas? I believe this question was asked many times and if we can solve it this time it will help a lot of people!

    http://wordpress.org/extend/plugins/wp-customer-reviews/

  2. kaylamatthews
    Member
    Posted 1 year ago #

    Some updates - i got the average rating to show on another page now, but only the first one works and the rest of the average ratings for DIFFERENT posts are all showing the same average rating result as the first one...

    I simply moved the "HTML rendering"

    $average_rating = 'Average Rating: <div class="sp_rating"><div class="base"><div class="average" style="width:'.$this->get_average_rating().'%"></div></div></div>';

    and "Inserting average rating into the template" codes

    $the_content .= $average_rating;

    Except now this becomes

    $reviews_content .= $average_rating;

    from above into the

    function output_reviews_show()

    function.

    I should be really close to getting it, I think the issue lies in the

    function get_average_rating()

    function, the line

    $this->get_aggregate_reviews($post->ID)

    the $post->ID is the culprit?

  3. dreddie27
    Member
    Posted 1 year ago #

    sorry i'm a newb so cant help. But did make a small donation to the developers in the hope it will keep them interested and help solve your problem. (after wich i can use it also :-)

  4. kaylamatthews
    Member
    Posted 1 year ago #

    Can anybody please help? I have hired a dev but he is unable to produce any results after 2 days...

  5. successwill
    Member
    Posted 1 year ago #

    Seems that its been 3 months but if you have found the solution, please tell me.

    i want to pull a hundred overall rating into a table which is on a separate "page".

    And i want to let the users to sort the table according to some criterias such as rating, year, new..etc..

    Any help.?

  6. kartguru
    Member
    Posted 10 months ago #

    @kaylamatthews

    I'd like to know if you eventually solved your issue and how (if you don't mind sharing)?

    Thanks

  7. kartguru
    Member
    Posted 10 months ago #

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic