Title: Wrong sorting
Last modified: August 21, 2016

---

# Wrong sorting

 *  [thepanz](https://wordpress.org/support/users/thepanz/)
 * (@thepanz)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/wrong-sorting/)
 * The sorting provided by the plugin is wrong if “menu_order” is choosen.
    Main
   reason: the sorting is provided by an (ugly??) create_function() call where string/
   number conversion wrongly evaluates numeric fields.
 * The usage of create_function is discouraged since PHP version 5.3
 * Why the the default WP get_posts() is not used? it already supports sorting!
 * My edits are visible in the following Github-Gist:
    [https://gist.github.com/thePanz/7827158/revisions](https://gist.github.com/thePanz/7827158/revisions)
 * [http://wordpress.org/plugins/eg-attachments/](http://wordpress.org/plugins/eg-attachments/)

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

 *  Plugin Author [emmanuelg](https://wordpress.org/support/users/emmanuelg/)
 * (@emmanuelg)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/wrong-sorting/#post-4386507)
 * Hi
 * I will check the “menu_order” issue.
    I use the method “create fonction”, because
   I keep DB queries in cache. If the same list of attachments is requested several
   times, with different order, I execute only 1 DB query.
 * Emmanuel.
 *  Thread Starter [thepanz](https://wordpress.org/support/users/thepanz/)
 * (@thepanz)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/wrong-sorting/#post-4386508)
 * I don’t get your point, you’re generating an hash with the query parameters, 
   thus including “order” and “orderby” parameters.
    With my edits the cache works
   exactly as before; in fact you’re sorting the attachments only after the DB query
   has been executed. Another reason would to keep in cache the attachments not 
   regarding their sorting; in that case you should create the cache hash without
   the two “order” and “orderby” paramseters.
 * Regards
 *  Plugin Author [emmanuelg](https://wordpress.org/support/users/emmanuelg/)
 * (@emmanuelg)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/wrong-sorting/#post-4386522)
 * Hi
 * You are right.
    What I explained is the behavior before the 2.0.0. Then I changed
   the cache…
 * A sort function is still required if we want to sort attachments according date(
   file modified), or size.
 * I will review this question for the coming version.
 * Emmanuel.

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

The topic ‘Wrong sorting’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/eg-attachments_fbfbfb.svg)
 * [EG-Attachments](https://wordpress.org/plugins/eg-attachments/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/eg-attachments/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/eg-attachments/)
 * [Active Topics](https://wordpress.org/support/plugin/eg-attachments/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/eg-attachments/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/eg-attachments/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [emmanuelg](https://wordpress.org/support/users/emmanuelg/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/wrong-sorting/#post-4386522)
 * Status: not resolved