Title: Bug: Sorting with pagination
Last modified: August 24, 2016

---

# Bug: Sorting with pagination

 *  Resolved [Matt Harrison](https://wordpress.org/support/users/matt-h/)
 * (@matt-h)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/bug-sorting-with-pagination/)
 * I found a bug in the sorting of properties when using pagination.
 * Basically with the pagniation, if more than properties had the exact same price
   for sorting and they were right on the edge of a page break (last on one page
   and first on the next page). It would randomly choose which to show on each page(
   depending on the order MySQL chose with the limit). Basically this was making
   the same property show on multiple pages and some of them never show up.
 * I fixed it by adding the Post ID as a second order attribute so the sorting was
   consistent if the price was the same so they always showed in the same order.
 * The patch for the fix is here
 *     ```
       Index: core/class_functions.php
       ===================================================================
       --- core/class_functions.php
       +++ core/class_functions.php
       @@ -3696,7 +3696,7 @@
                      FROM {$wpdb->posts} AS p
                      WHERE p.ID IN ( " . implode( ",", $matching_ids ) . ")
                      {$additional_sql}
       -              ORDER BY {$meta_value} {$sql_sort_order}
       +              ORDER BY {$meta_value}, p.ID {$sql_sort_order}
                      {$limit_query}" );
   
                }
       @@ -3707,7 +3707,7 @@
                  SELECT ID FROM {$wpdb->posts } AS p
                  WHERE ID IN (" . implode( ",", $matching_ids ) . ")
                  $additional_sql
       -          ORDER BY $sql_sort_by $sql_sort_order
       +          ORDER BY $sql_sort_by, ID $sql_sort_order
                  $limit_query" );
   
              }
       ```
   
 * [https://wordpress.org/plugins/wp-property/](https://wordpress.org/plugins/wp-property/)

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

 *  Plugin Contributor [Maxim Peshkov](https://wordpress.org/support/users/maximpeshkov/)
 * (@maximpeshkov)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/bug-sorting-with-pagination/#post-6150981)
 * Hello.
 * Thank you for pointing to the issue. We will add the fix to next WP-Property 
   release.
 * Note, you can use [GitHub Repository](https://github.com/wp-property/wp-property)
   to pull your fixes.
 * Regards
 *  Thread Starter [Matt Harrison](https://wordpress.org/support/users/matt-h/)
 * (@matt-h)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/bug-sorting-with-pagination/#post-6150982)
 * Thanks, in the future I’ll make a pull request. I wasn’t aware of the github 
   repo, I looked around for one but didn’t see the link on the plugin page or your
   website.
 *  Plugin Contributor [Eric Sopp](https://wordpress.org/support/users/ideric/)
 * (@ideric)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/bug-sorting-with-pagination/#post-6150984)
 * Thanks Matt!

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

The topic ‘Bug: Sorting with pagination’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-property_c36510.svg)
 * [WP-Property - WordPress Powered Real Estate and Property Management](https://wordpress.org/plugins/wp-property/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-property/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-property/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-property/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-property/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-property/reviews/)

 * 3 replies
 * 3 participants
 * Last reply from: [Eric Sopp](https://wordpress.org/support/users/ideric/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/bug-sorting-with-pagination/#post-6150984)
 * Status: resolved