"Natural" sorting for ElementCriteria I want something sorted like this:


MyString8
MyString9
MyString10
MyString11


$criteria-&gt;order = 'myField asc doesn't get things quite right, as MySQL has not native "natural sorting".
You can fake it by first sorting by character length, and then by the value: $criteria-&gt;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.