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

<p>Here’s what I would recommend:</p>

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

<pre><code>{firstName} {lastName}
</code></pre></li>
<li><p>Add the “First Name” and “Last Name” fields to the entry type’s field layout</p></li>
<li>Save the entry type</li>
<li>Update your existing People entries</li>
</ul>

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

<pre><code>{% set entries = craft.entries.section('people').order('lastName asc').limit(0) %}
</code></pre>

CC BY-SA 3.0
2015-10-09T00:08:34.500Z
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!
Kenyon Kowal
CC BY-SA 3.0
2015-10-09T00:21:36.640Z
@KenyonKowal Gotcha. Just added a new answer that should work for you.
Brandon Kelly
CC BY-SA 3.0
2015-10-09T00:02:49.370Z
2015-10-09T00:02:49.370Z
Brandon Kelly
<p>Another option is to use the <a href="https://github.com/aelvan/Preparse-Field-Craft" rel="nofollow">Preparse</a> plugin to automatically parse out and store last names in a hidden field.</p>

<ul>
<li>Install the Preparse plugin</li>
<li>Create a new “Last Name” field using the Preparse field type</li>
<li><p>Set the field’s Twig template setting to this:</p>

<pre><code>{{ entry.title|split(' ')|last }}
</code></pre></li>
<li><p>Edit the People section’s entry type settings, and add the Last Name field to its field layout.</p></li>
<li>Edit the People section’s main settings - just re-save them, so that all of your existing entries get updated.</li>
</ul>

<p>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:</p>

<pre><code>{% set entries = craft.entries.section('people').order('lastName asc').limit(0) %}
</code></pre>

CC BY-SA 3.0
2015-10-09T00:21:21.443Z
2015-10-09T00:21:21.443Z
Brandon Kelly
<p>I would like to get the last string of a entry title and order entries based on that. Basically the <code>people</code> title are their full names and I am trying to find their last name and filter based on that, instead of their first name.</p>

<p><code>{% set entries = craft.entries.section('people').order('title').limit(0) %}</code></p>

<p>similar to this <code>entry.title|split(' ')|last</code></p>

<entries><entry><order><set>
Order entries based on last string of title
# Order entries based on last string of title

(Asked by: username_0 on 2015-10-08)

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`

**Tags:** entries, entry, order, set

---

## 2 answers

### Answer by username_1 on 2015-10-09. Score: 3 | Accepted answer

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) %}

> **Comments:**
> **username_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!  
> **username_1**: @KenyonKowal Gotcha. Just added a new answer that should work for you.  

---

### Answer by username_1 on 2015-10-09. Score: 4

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) %}


---

