Display vote stats

<?php function showTopRatedPostsStats($num_posts, $blog_id=1) { global $wpdb; $rows = $wpdb->get_results( $wpdb->prepare(" SELECT post_id, SUM(vote) as tot_vote FROM {$wpdb->prefix}wdpv_post_votes WHERE blog_id = %d GROUP BY post_id ORDER BY tot_vote DESC LIMIT %d", $blog_id, $num_posts), OBJECT ); switch_to_blog($blog_id); ob_start(); foreach( $rows as $i => $row ) { $tot_vote = $row->tot_vote; $post_id = $row->post_id; $post = get_post($post_id); $blog_title = get_bloginfo(); //Post type $posttype= get_post_type( $post_id ); ?> <?php if ( get_post_status ( $post_id ) == 'publish' ) { ?> <li class="posttype-<?=$posttype?> postid-<?=$post_id?> blogid-<?=$blog_id?> position-<?=$i?>"> <div class="col-md-6"> <h4 class="idea-title"><a href="<?=get_permalink($post_id);?>"><?=$post->post_title?></a></h4> </div> <div class="col-md-2"> <p class="side-vote-count"><?=$tot_vote?> votes</p> </div> <div class="col-md-2"> <p class="side-vote-count">( votes)</p> </div> <div class="col-md-2"> <p class="side-vote-count">( votes)</p> </div> </li> <?php } ?> <?php } $html = ob_get_contents(); ob_end_clean(); restore_current_blog(); return $html; } ?>

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.