Skip to content

Instantly share code, notes, and snippets.

@jaymiejones86
Created May 5, 2014 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaymiejones86/11529513 to your computer and use it in GitHub Desktop.
Save jaymiejones86/11529513 to your computer and use it in GitHub Desktop.
<?php
$args = array(
'post_type' => 'review',
'post_status' => 'publish',
'posts_per_page' => '-1',
'orderby' => 'ID',
'order' => 'DESC',
);
$limit = 5;
$limit_count = 0;
$ratings = array();
$reviews = array();
query_posts( $args );
while ( have_posts() ) : the_post();
if ($limit_count < 5) {
$reviews[] = array(
"reviewed_by" => get_field('reviewed_by', $post->ID),
"reviewed_from" => get_field('reviewed_from', $post->ID),
"content" => $post->post_content
);
$limit++;
}
$ratings[] = get_field('reviewed_rating', $post->ID);
endwhile;
$ratings_total = array_sum($ratings);
$ratings_count = count($ratings);
$average_rating = number_format(($ratings_total / $ratings_count), 1, '.', '');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment