Title: Sorting Posts by Vote Count
Last modified: August 20, 2016

---

# Sorting Posts by Vote Count

 *  [anjan.dev.phukan](https://wordpress.org/support/users/anjandevphukan/)
 * (@anjandevphukan)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/sorting-posts-by-vote-count/)
 * I am using the following code, to show the posts in vote count order.
 *     ```
       <?php
       /**
        * SORTS THE POSTS BY VOTE COUNT
        */
       add_filter('posts_orderby', 'edit_posts_orderby');
       add_filter('posts_join_paged','edit_posts_join_paged');
   
       function edit_posts_join_paged($join_paged_statement) {
           global $wpdb;
           $join_paged_statement = "LEFT JOIN ".$wpdb->prefix."wpv_voting ON ".$wpdb-       >prefix."wpv_voting.post_id = $wpdb->posts.ID";
           return $join_paged_statement;
       }
   
       function edit_posts_orderby($orderby_statement) {
           global $wpdb;
           $orderby_statement = "(".$wpdb->prefix."wpv_voting.vote_count) DESC";
           return $orderby_statement;
       }
       ?>
       ```
   
 * It works fine for the listing page. But when I go to a category, it doesn’t show
   any result.
 * Please help.
 * [http://wordpress.org/extend/plugins/wp-voting/](http://wordpress.org/extend/plugins/wp-voting/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [waterhead](https://wordpress.org/support/users/waterhead/)
 * (@waterhead)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/sorting-posts-by-vote-count/#post-3228133)
 * I post here because similar topic :D.
 * How to put vote down and up? and number what position post has? Like first post
   is number one etc.
 *  [dreamgrowers](https://wordpress.org/support/users/dreamgrowers/)
 * (@dreamgrowers)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/sorting-posts-by-vote-count/#post-3228134)
 * I would also know how to get this to sort the category posts instead of breaking
   them.
 *  [domdino](https://wordpress.org/support/users/domdino/)
 * (@domdino)
 * [12 years, 10 months ago](https://wordpress.org/support/topic/sorting-posts-by-vote-count/#post-3228150)
 * Another vote for this!! 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Sorting Posts by Vote Count’ 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/)

## Tags

 * [sort](https://wordpress.org/support/topic-tag/sort/)

 * 3 replies
 * 4 participants
 * Last reply from: [domdino](https://wordpress.org/support/users/domdino/)
 * Last activity: [12 years, 10 months ago](https://wordpress.org/support/topic/sorting-posts-by-vote-count/#post-3228150)
 * Status: not resolved