Answers.Body: <p>It's possible to pass MySQL functions to the <code>order</code> parameter. <a href="https://www.copterlabs.com/natural-sorting-in-mysql/" rel="nofollow noreferrer">Using the MySQL <code>LENGTH</code> function</a>, I believe the following should do the trick <em>(assuming your "model number" field's handle is <code>modelNumber</code>)</em>:</p>
  
  <pre><code>{% set entries = craft.entries.section('yourSection').order('LENGTH(modelNumber) asc, modelNumber asc') %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-10T19:55:03.973Z
Answers.LastActivityDate: 2016-11-10T20:22:47.473Z
Answers.LastEditDate: 2016-11-10T20:22:47.473Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>I've encountered a similar problem as in this post: <a href="https://craftcms.stackexchange.com/q/8931/4468">How to order numbers naturally?</a></p>
  
  <p>I have some products I need sorted on a page by model number, and currently they sort as ABC-1, ABC-12, ABC-2, etc. instead of ABC-1, ABC-2, ABC-12. Is it possible to extend the existing methods or create a custom sort method to use with the order parameter, rather than using a twig filter as suggested in the link above?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-09T23:04:47.437Z
Comments.Text: The only way to extend the stock Twig methods (or create a custom method) is to [write your own plugin](https://cameronspear.com/blog/craft-cms-twig-filter-extension/) – why not just use [SuperSort](https://github.com/TopShelfCraft/SuperSort) (referenced in the answer you linked to), which already handles this sort of thing beautifully?
Comments.UserDisplayName: Mats Mikkel Rummelhoff
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-10T13:22:22.033Z
Comments.Text: The page I'm working on has a dropdown that users can select sort order from. The corresponding sort method is then passed into .order() and the page is updated. There are certain scenarios that I'm not sure the plugins will work as they use Twig filters. For example, one method sorts between items flagged as new products and those that aren't, then within those two segments sorts them alphabetically by product number. I've updated my original question to reflect that I'm trying to avoid Twig filters.
Comments.UserDisplayName: Joel
Tags: <order><sort>
Title: Extend order methods to sort numbers naturally
ThreadText: # Extend order methods to sort numbers naturally
  
  (Asked by: username_0 on 2016-11-09)
  
  I've encountered a similar problem as in this post: [How to order numbers naturally?](https://craftcms.stackexchange.com/q/8931/4468)
  
  I have some products I need sorted on a page by model number, and currently they sort as ABC-1, ABC-12, ABC-2, etc. instead of ABC-1, ABC-2, ABC-12. Is it possible to extend the existing methods or create a custom sort method to use with the order parameter, rather than using a twig filter as suggested in the link above?
  
  **Tags:** order, sort
  
  > **Comments:**
  > **username_1**: The only way to extend the stock Twig methods (or create a custom method) is to [write your own plugin](https://cameronspear.com/blog/craft-cms-twig-filter-extension/) – why not just use [SuperSort](https://github.com/TopShelfCraft/SuperSort) (referenced in the answer you linked to), which already handles this sort of thing beautifully?  
  > **username_0**: The page I'm working on has a dropdown that users can select sort order from. The corresponding sort method is then passed into .order() and the page is updated. There are certain scenarios that I'm not sure the plugins will work as they use Twig filters. For example, one method sorts between items flagged as new products and those that aren't, then within those two segments sorts them alphabetically by product number. I've updated my original question to reflect that I'm trying to avoid Twig filters.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-11-10. Score: 1 | Accepted answer
  
  It's possible to pass MySQL functions to the `order` parameter. [Using the MySQL `LENGTH` function](https://www.copterlabs.com/natural-sorting-in-mysql/), I believe the following should do the trick *(assuming your "model number" field's handle is `modelNumber`)*:
  
  ```
  {% set entries = craft.entries.section('yourSection').order('LENGTH(modelNumber) asc, modelNumber asc') %}
  
  ```
  
  
  ---
  
  