<p>Something like this should do what you're looking for:</p>

<pre><code>{% if not object.id %}{{ craft.entries.section('scripts').order('postDate DESC').first().title + 1 }}{% else %}{{ object.title }}{% endif %}
</code></pre>

CC BY-SA 3.0
2017-07-07T21:44:40.200Z
Is there a way to make this trigger ONLY when a brand new entry is saved? When the entry is updated and saved the title continues to be changed.
Steven Thate
CC BY-SA 3.0
2017-07-08T02:36:03.700Z
Updated answer...
Brad Bell
CC BY-SA 3.0
2017-07-11T20:32:24.623Z
Amazing. Thank you so much! I had no idea that a field could be so powerful...
Steven Thate
CC BY-SA 3.0
2017-06-30T19:31:02.330Z
2017-07-08T02:35:56.060Z
2017-07-08T02:35:56.060Z
Brad Bell
<p>I am attempting to make one of my sections use auto-generated titles. I am making my first entry with a title like <code>8000</code>. What I need is the second entry to be titled <code>8001</code>, the third <code>8002</code>, etc. <strong>Each entry must have a unique title in sequence.</strong></p>

<p><strong>This is the Title Format I tried using:</strong></p>

<p><code>{{ craft.entries.section('scripts').last().title + 1 }}</code></p>

<p>I created a test entry after that and it successfully generated a title similar to the last entry plus one. <strong>However</strong>, when I created a second test entry, the title remained the same as the first test entry, but the slug was <code>titlexx-1</code>. I made another test entry, same thing, with the slug <code>titlexx-2</code>.</p>

<p>What am I missing in my Title Format?</p>

<p>Thanks for the help!</p>

<titles><auto-generate>
Auto-generated title based on last entry
# Auto-generated title based on last entry

(Asked by: username_0 on 2017-06-30)

I am attempting to make one of my sections use auto-generated titles. I am making my first entry with a title like `8000`. What I need is the second entry to be titled `8001`, the third `8002`, etc. **Each entry must have a unique title in sequence.**

**This is the Title Format I tried using:**

`{{ craft.entries.section('scripts').last().title + 1 }}`

I created a test entry after that and it successfully generated a title similar to the last entry plus one. **However**, when I created a second test entry, the title remained the same as the first test entry, but the slug was `titlexx-1`. I made another test entry, same thing, with the slug `titlexx-2`.

What am I missing in my Title Format?

Thanks for the help!

**Tags:** titles, auto-generate

---

## 1 answers

### Answer by username_1 on 2017-06-30. Score: 1 | Accepted answer

Something like this should do what you're looking for:
{% if not object.id %}{{ craft.entries.section('scripts').order('postDate DESC').first().title + 1 }}{% else %}{{ object.title }}{% endif %}

> **Comments:**
> **username_0**: Is there a way to make this trigger ONLY when a brand new entry is saved? When the entry is updated and saved the title continues to be changed.  
> **username_1**: Updated answer...  
> **username_0**: Amazing. Thank you so much! I had no idea that a field could be so powerful...  

---

