2

I want something sorted like this:

  • MyString8
  • MyString9
  • MyString10
  • MyString11

$criteria->order = 'myField asc doesn't get things quite right, as MySQL has not native "natural sorting".

2

You can fake it by first sorting by character length, and then by the value: $criteria->order = 'CHAR_LENGTH(myField) asc, myField asc

Its not perfect, but in certain cases, it will be all you need. Other methods exist as well: https://stackoverflow.com/a/8557307/935398

Note: CHAR_LENGTH is a MySQL function that is getting passed directly to the ORDER BY clause. It has nothing to do with Craft directly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.