Title: Natural Sorting
Last modified: August 30, 2016

---

# Natural Sorting

 *  [Matt](https://wordpress.org/support/users/syntax53/)
 * (@syntax53)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/natural-sorting/)
 * Any way to employ natural sorting of file names?
 * e.g. right now the following sort would happen:
 * “1 file one”
    “2 file two” “21 file twenty one” “3 file three”
 * [https://wordpress.org/plugins/file-away/](https://wordpress.org/plugins/file-away/)

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

 *  [kat_arteria](https://wordpress.org/support/users/kat_arteria/)
 * (@kat_arteria)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/natural-sorting/#post-6221262)
 * I too, would like to know the answer to this!
 *  Thread Starter [Matt](https://wordpress.org/support/users/syntax53/)
 * (@syntax53)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/natural-sorting/#post-6221394)
 * I tried to fix this myself today and I’m a little confused as it looks like you
   guys do it already, but it’s not working for whatever reason.
    In inc.sort.php
   you have …
 *     ```
       if(phpversion() < '5.4') array_multisort($rawnames, SORT_ASC, SORT_STRING, $links, $locs, $exts, $fulls, $dirs, $times, $dynamics);
       	else array_multisort($rawnames, SORT_ASC, SORT_NATURAL, $links, $locs, $exts, $fulls, $dirs, $times, $dynamics);
       ```
   
 * … and when I check the debug output of $rawnames they get sorted properly with
   SORT_NATURAL. However, the don’t end up displaying that way. At least not with
   the table view. If I do a list view with recursive=”on” it displays properly.
   But as soon as I do a table view (or directories=”on”, which seems to enforce
   table mode), the sorting is off again.
 * I was assuming the table is doing it’s own sorting after it’s drawn or something
   but I can’t find it.
 * Thanks
 *  Thread Starter [Matt](https://wordpress.org/support/users/syntax53/)
 * (@syntax53)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/natural-sorting/#post-6221399)
 * So I figured it out and it’s a combination of two things. So #1) In inc.directories.
   php you are not sorting the directory listing (natural or otherwise). On line
   47 you have:
 * `foreach(glob("$dir"."/*", GLOB_ONLYDIR) as $k=> $folder)`
 * and if I modify that and do this instead:
 *     ```
       $dir_array = glob("$dir"."/*", GLOB_ONLYDIR);
       if(phpversion() < '5.4') array_multisort($dir_array, SORT_ASC, SORT_STRING);
       else array_multisort($dir_array, SORT_ASC, SORT_NATURAL);
       foreach($dir_array as $k=> $folder)
       ```
   
 * and also add a ‘ sortfirst=”disabled” ‘ to the shortcode, the listing is then
   sorted properly. If I don’t disable the sorting then the javascript in footable.
   js screws up the sorting again.

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

The topic ‘Natural Sorting’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/file-away_e3e2e1.svg)
 * [File Away](https://wordpress.org/plugins/file-away/)
 * [Support Threads](https://wordpress.org/support/plugin/file-away/)
 * [Active Topics](https://wordpress.org/support/plugin/file-away/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/file-away/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/file-away/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Matt](https://wordpress.org/support/users/syntax53/)
 * Last activity: [10 years, 10 months ago](https://wordpress.org/support/topic/natural-sorting/#post-6221399)
 * Status: not resolved