Support » Plugin: Site Reviews » Get the average reviews value for a post with a php function ?

  • Resolved Mxlaxe

    (@mxlaxe)


    Hi,

    After looking through the documentation I couldn’t find how to get the average programmatically.

    I would like to have a php function like :

    get_reviews_average($post->ID);

    which would return a float number like “4.5” for example.

    The result would be the average score for all the reviews of a particular post.

    Additionnaly, it would be awesome to have a similar function but to display the stars only. I know there is a shortcode that does it : do_shortcode( “[site_reviews_summary assigned_to={$post->ID} hide=bars,summary,rating]” ) but I would prefer to have a php function.

    Thanks for your help and congrats for the efforts given into this awesome plugin.

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

    (@geminilabs)

    If the page has been assigned reviews, you can get the average rating like this:

    $averageRating = get_post_meta( $post->ID, '_glsr_average', true );
    

    The shortcode can also be used like this:

    $starRating = do_shortcode( '[site_reviews_summary assigned_to=post_id hide=bars,summary,rating]' );
    
    Mxlaxe

    (@mxlaxe)

    Awesome! I didn’t know there was a meta field for the average.

    Thanks for the fast reply

    Plugin Author Gemini Labs

    (@geminilabs)

    No problem. May I mark this as resolved?

    Mxlaxe

    (@mxlaxe)

    Sure, I forgot to check the box in the previous reply.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get the average reviews value for a post with a php function ?’ is closed to new replies.