I'm trying to order my users with craft.users.order('lastName'), which should be no problem, since I'm pulling that straight from the documentation; however, it's not working for some reason. Is this a current a bug in Craft?

Currently, I have users with these last names: Apple, Campbell, Jackson.

With order('lastName'), it's printing out: Campbell, Jackson, Apple. So no alphabetical order is being applied asc or desc.

1 Answer 1


Values in the documentation list possibilities, like: 'firstName' and 'lastName', which needs to be updated, since Craft only accepts lowercase values.

Changing 'firstName' to 'firstname' solves the issue.

  • 2
    Can you point to an example in the docs?
    – Brad Bell
    Oct 15, 2015 at 18:19
  • I too spent a lot of time attempting to order users by lastName and couldn't figure out why it wasn't working. Fortunately, I found this post and changed the criteria to {order:'lastname'}, which worked. @BradBell The user order docs show the camelCase criteria values as working, but only the lowercase values seem to work in practice. Aug 31, 2017 at 13:09
  • 1
    @AaronWaldon weird... the value of order gets passed directly into the SQL query that is generated and mapped back to the specified table columns. MySQL table columns are supposed to be case insensitive, so either should work. Tested locally and it's that way for me.
    – Brad Bell
    Aug 31, 2017 at 17:59
  • I'm super grateful for this post. I just spent 90 minutes trying to debug my users being sorted arbitrarily, and trying (unsuccessfully) to find some way around it. This is still an issue in Craft 3.3. Thank you! Incidentally, I was debugging the raw MySQL query, and it wasn't sorting by users.firstName.... it was sorting by content.field_firstName—a field I happen to have but whose results in the query (after several joins) were all NULL.
    – nmjk
    Jan 30, 2020 at 0:09
  • Craft CMS 3.7.28 and the issue is still there.
    – Mosswalker
    Jan 10, 2022 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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