I would like to get the last string of a entry title and order entries based on that. Basically the people title are their full names and I am trying to find their last name and filter based on that, instead of their first name.

{% set entries = craft.entries.section('people').order('title').limit(0) %}

similar to this entry.title|split(' ')|last

2 Answers 2


It’s not possible to do that unless you’ve already got the last word saved somewhere.

Here’s what I would recommend:

  • Create two new Plain Text fields - “First Name” and “Last Name”
  • Go to your People section’s entry type settings
  • Uncheck the “Show the Title field?” setting and set the “Title Format” setting to:

    {firstName} {lastName}
  • Add the “First Name” and “Last Name” fields to the entry type’s field layout

  • Save the entry type
  • Update your existing People entries

With those changes made, you will now be able to order directly by your Last Name field’s values:

{% set entries = craft.entries.section('people').order('lastName asc').limit(0) %}
  • Oh ok, ya unfortunately these titles we're imported from wordpress so the title tags were already populated and we have 122 people so redoing them all is too big of a task. Thanks anyway! Oct 9, 2015 at 0:08
  • @KenyonKowal Gotcha. Just added a new answer that should work for you. Oct 9, 2015 at 0:21

Another option is to use the Preparse plugin to automatically parse out and store last names in a hidden field.

  • Install the Preparse plugin
  • Create a new “Last Name” field using the Preparse field type
  • Set the field’s Twig template setting to this:

    {{ entry.title|split(' ')|last }}
  • Edit the People section’s entry type settings, and add the Last Name field to its field layout.

  • Edit the People section’s main settings - just re-save them, so that all of your existing entries get updated.

Now when your People entries are saved, the last word in their Title will be copied over to a hidden “Last Name” field, and you can sort by that in your template:

{% set entries = craft.entries.section('people').order('lastName asc').limit(0) %}

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.