Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Funtion to retrieve a message with the ratings of a particular taxonomy
- add_shortcode( 'show-testimonials-custom', 'ttshowcase_get_reviews' );
- function ttshowcase_get_reviews($atts) {
- $tsargs = array(
- 'post_type' => 'ttshowcase',
- 'tax_query' => array(
- array(
- 'taxonomy' => 'ttshowcase_groups',
- 'field' => 'slug',
- 'terms' => $atts['slug'],
- ),
- ),
- );
- //perform the query
- $tts_query = new WP_Query( $tsargs );
- //store the ratings in an array
- $collection = array(
- '0' => 0,
- '1' => 0,
- '2' => 0,
- '3' => 0,
- '4' => 0,
- '5' => 0
- );
- $total = 0;
- while ( $tts_query->have_posts() ) : $tts_query->the_post();
- //get rating value;
- $rating = get_post_meta( get_the_ID(), '_aditional_info_rating', true );
- //add it to collection array
- $collection[$rating] = $collection[$rating]+1;
- $total++;
- endwhile;
- $output = '';
- foreach ($collection as $key => $value) {
- //show only if there were ratings with that value
- if($value>0) {
- //build output
- $output .= 'Rating '.$key.' = '.$value.' times <br>';
- }
- }
- //add total rating count
- $output .= 'Total ratings:'.$total;
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment