Title: [Plugin: WP Voting] Post Ranking
Last modified: August 20, 2016

---

# [Plugin: WP Voting] Post Ranking

 *  Resolved [vusisindane](https://wordpress.org/support/users/vusisindane/)
 * (@vusisindane)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/)
 * Hi there, I’m trying to get the ‘rank’ of a post according to the number of votes
   it has. e.g. let’s say I have 3 posts.
    POSTA = 10 votes POSTB = 20 votes POSTC
   = 30 votes.
 * Then POSTC should be ranked #1, POSTB #2 etc. I want to write a function that
   gets that rank. Is there an easier way to get this done? or should I just go 
   ahead and hack the plugin?
 * [http://wordpress.org/extend/plugins/wp-voting/](http://wordpress.org/extend/plugins/wp-voting/)

Viewing 15 replies - 1 through 15 (of 33 total)

1 [2](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/page/2/?output_format=md)

 *  Plugin Author [Ko Min](https://wordpress.org/support/users/tristanmin/)
 * (@tristanmin)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/#post-2379207)
 * Hi,
 * I am going to do as a widget or shortcode. It will be included in next release.
 * Cheers!
 *  [razzgpe](https://wordpress.org/support/users/razzgpe/)
 * (@razzgpe)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/#post-2379245)
 * Hey tristanmin.
 * When do you will release the new version with ranking?
    I need it for a project
   for my university.
 * Greetings from Germany!
    Alex
 *  Thread Starter [vusisindane](https://wordpress.org/support/users/vusisindane/)
 * (@vusisindane)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/#post-2379250)
 * I’ve actually implemented it. If you want I can give you the code…
    please see
   [http://www.be1idea.org/ideas/the-joy-of-physics/](http://www.be1idea.org/ideas/the-joy-of-physics/)
 *  [razzgpe](https://wordpress.org/support/users/razzgpe/)
 * (@razzgpe)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/#post-2379251)
 * Wow! That would be pretty cool!
    It looks very nice!
 * My Emailadress:
    elecsander[at]gmail.com
 * Thank you very much!
    Greetings from Germany! Alex
 *  Thread Starter [vusisindane](https://wordpress.org/support/users/vusisindane/)
 * (@vusisindane)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/#post-2379258)
 * What I will do is build an independent plugin that hooks into this one so that
   we can allow the original author to continue working on his plugin without disturbing
   the process.
 * Please give me until Saturday to do this for you…
 * P.S
    Greetings from South Africa 🙂
 *  [razzgpe](https://wordpress.org/support/users/razzgpe/)
 * (@razzgpe)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/#post-2379262)
 * Wow! That is so cool! With a rank the WP Vote Plugin is perfect!
    Thank you very
   much for your engagement!
 * I will post my project with both plugins, when I finsh it.
 * Best regards from Germany! 🙂
 *  [razzgpe](https://wordpress.org/support/users/razzgpe/)
 * (@razzgpe)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/#post-2379284)
 * Hey!
 * Do you have the solution?
    It would be nice, when you could give me the code.
   I just need the code to paste it in the loop.
 * I have two loops.
 * The normal loop: [http://goo.gl/WjtHF](http://goo.gl/WjtHF)
    The random loop:
   [http://goo.gl/dibKA](http://goo.gl/dibKA)
 * And now I need the code for “The ranking loop” with a ranking of the votes of
   WP Voting.
 * When you or tristanmin could help me, then it would be pretty cool!!
 * Greetings from Germany!
 *  Thread Starter [vusisindane](https://wordpress.org/support/users/vusisindane/)
 * (@vusisindane)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/#post-2379285)
 * Sorry, my weekend turned out to be a disaster. I’m working on it as we speak.
   Will send it through.
 *  Thread Starter [vusisindane](https://wordpress.org/support/users/vusisindane/)
 * (@vusisindane)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/#post-2379292)
 * things have been super hectic. so please accept this code rather than the entire
   widget. you can look up on wordpress codex on how to make a widget
 *     ```
       function b1_get_post_rank($post)
       {
       	global $wpdb;
   
       	$total_posts = $wpdb->get_var('SELECT COUNT( DISTINCT vote_count)
       					   	FROM ' . $wpdb->prefix . 'wpv_voting');
   
       	$total_smaller = $wpdb->get_var('SELECT COUNT( DISTINCT vote_count )
       					   	FROM ' . $wpdb->prefix . 'wpv_voting
       						WHERE vote_count < (SELECT vote_count
       											FROM ' . $wpdb->prefix . 'wpv_voting
       											WHERE post_id = ' . $post->ID . ')');
   
       	$rank = $total_posts - $total_smaller;
   
       	return $rank;
       }
       ```
   
 *  Thread Starter [vusisindane](https://wordpress.org/support/users/vusisindane/)
 * (@vusisindane)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/#post-2379293)
 * Feel free to improve it and let me know (and let the plugin author know) if you
   do.
 *  [razzgpe](https://wordpress.org/support/users/razzgpe/)
 * (@razzgpe)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/#post-2379294)
 * Thank you very much!
    How can I get the ranking?
 * <?php b1_get_post_rank($post) ?> doesn’t work.
 * I also tried to get the rank into this loop:
 *     ```
       <?php
       /*
       Template Name: Ranking
       */
       ?>
       <?php get_header(); ?>
           <?php
           if (is_page('ranking')) {
           b1_get_post_rank($post);
           include(TEMPLATEPATH."/index.php");
           } else { ?>
       <!--Page Content-->
           <?php } ?>
       <?php get_footer(); ?>
       ```
   
 * But it doesn’t work!
 * Thank you very much for your code-solution.
    I hope, you can help me again! :-/
 * Best regards,
    Razz
 *  Thread Starter [vusisindane](https://wordpress.org/support/users/vusisindane/)
 * (@vusisindane)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/#post-2379295)
 * 1. you must paste that code I gave you in your functions.php
    2. in your template(
   or in your loop) you can call that function i.e.
 * `<?php echo b1_get_post_rank($post) ?>`
 * It should return an int (number), that number is the rank of the post. One thing
   though, just make sure the $post is actually a valid variable. if $post is null,
   then it won’t work. one way to get the post is to use `<?php global $post; ?>`(
   provided wordpress has declared it)
 *  Plugin Author [Ko Min](https://wordpress.org/support/users/tristanmin/)
 * (@tristanmin)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/#post-2379298)
 * Oh guys! I didn’t know that you guys are implementing top voted feature. I got
   a lot of work to do at my primary job. So I couldn’t check this blog post lately.
   If I knew it early, that make me a lot easier to develop the top voted widget.
   Anyway, I’ve finished the top voted widget and which is included in version 1.7.
   Please let me know if you need my help.
 * Thanks for all the contributors and supporters.
 * Cheers!
 *  Thread Starter [vusisindane](https://wordpress.org/support/users/vusisindane/)
 * (@vusisindane)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/#post-2379299)
 * Thanks.
    Will definitely check it out.
 *  [razzgpe](https://wordpress.org/support/users/razzgpe/)
 * (@razzgpe)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/#post-2379300)
 * Hey! I couldn’t get it to work! 😀
    With the solution of vusisindane it works,
   that I get a number of the rank. But I’m just a PHP rookie and I can’t make a
   loop-ranking site with all posts in a ranking.
 * I’m working on a project-site for my university and need a site, where I can 
   sort the projects ( = posts/blogarticles) by the ranking
 * [http://goo.gl/a8JeO](http://goo.gl/a8JeO)
 * So I’m happy, when you release 1.7.
    When is the release-date?
 * Greetings from Germany!

Viewing 15 replies - 1 through 15 (of 33 total)

1 [2](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/page/2/?output_format=md)

The topic ‘[Plugin: WP Voting] Post Ranking’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-voting.svg)
 * [WP Voting](https://wordpress.org/plugins/wp-voting/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-voting/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-voting/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-voting/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-voting/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-voting/reviews/)

 * 33 replies
 * 8 participants
 * Last reply from: [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-wp-voting-post-ranking/page/3/#post-2379358)
 * Status: resolved