I'm using the Vote it up plugin.

Is there a way of placing the two most voted posts at the top? (Like in Youtube)?

I'm not very sure if this is hard or easy to accomplish.


Someone posted a method in the Wordpress forums here, but Mike Schindel said:

This example is absolutely AWFUL. It may work but it's far more code than you needs and may break on a future version of WordPress.

I've been playing with Wordpress for a while but Im still a PHP beginner.

Is there a way of fixing that code posted in the Wordpress forums? Or a better method?

2 Answers 2


a while back i used that plugin and i needed a way to list most voted posts so after looking at the plugin's widget code and i came up with this function:

function top_voted($number){
    $a = SortVotes();
    echo '<div class="voted">';
    $rows = 0;
    //Now does not include deleted posts
    $i = 0;
    while ($rows < $number)) {
        if ($a[0][$i][0] != '') {
                $postdat = get_post($a[0][$i][0]);
            if (!empty($postdat)) {
                echo '<div class="fore">';
                echo '<div class="votecount" style="width: 1em; color: #555555; font-weight: bold;">'.$a[1][$i][0].' </div><div><a href="'.$postdat->guid.'" title="'.$postdat->post_title.'">'.$postdat->post_title.'</a></div>';
                echo '</div>';
        if ($i < count($a[0])) {
        } else {
            break; //exit the loop
    echo '</div>';


  • So the first part goes to functions.php and the usage part: top_voted(5); goes inside The Loop? or all that code (the first part and the usage part) goes in a template file?
    – wyc
    Commented Feb 25, 2011 at 19:44
  • 1
    i cant remeber but you can try to add the function to the functions.php and the top_voted(5); replaces the loop, so you dont need the loop at all.
    – Bainternet
    Commented Feb 25, 2011 at 19:58
  • Yeah I found that code in votingfunctions.php. Thanks!
    – wyc
    Commented Feb 25, 2011 at 20:02

I believe it would be using postmeta to save votes. I would do that by doing a query_post order by that meta value and get two posts & save their ID in an array and then again use query_posts with post__not_in to not to include those posts in the remaining loop

  • it uses its own tables and not postmeta.
    – Bainternet
    Commented Feb 25, 2011 at 19:42
  • Alrite, then with your solution, he can save IDs and exclude them in the regular loop.
    – Ashfame
    Commented Feb 25, 2011 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.