<p>If you are not going to update your current project to Craft 3 (which will break nearly all your templates and all plugins anyway) you don't need to bother about that message. This is only for Craft 3 and not for Craft 2.</p>

<p>Otherwise looking in the <a href="https://docs.craftcms.com/v3/changes-in-craft-3.html#element-queries" rel="nofollow noreferrer">docs</a> might be a good idea. You can do</p>

<pre><code>{% set query = craft.entries().section('news') %}
{% set total = query.count() %}
{% set last = query.nth(total - 1) %}
</code></pre>

<p>or </p>

<pre><code>{% set oldest = craft.entries()
    .section('news')
    .inReverse()
    .one() 
%}
</code></pre>

CC BY-SA 3.0
2017-11-30T01:29:46.070Z
So I am working in Craft 3 already and that link to the docs is very useful. I implemented `nth(query.count() - 1)` and it worked great. Thank you.
TRIM
CC BY-SA 3.0
2018-03-28T06:38:48.363Z
That docs link is now dead. This [one](https://github.com/craftcms/docs/blob/341b0d451507944dea8ba4bbefadce5a7298315d/en/changes-in-craft-3.md#last)  might be comparable. It also suggests: In most cases you can replace calls to `.last()` with `.inReverse().one()`
kr37
CC BY-SA 4.0
2020-03-08T13:33:30.673Z
@kr37 your link is now dead as well. Any updated?
Christopher Healey
CC BY-SA 4.0
2020-03-09T14:22:24.727Z
At this point, I'd say go to [https://docs.craftcms.com/v3/](https://docs.craftcms.com/v3/) and search for inReverse
kr37
CC BY-SA 4.0
2017-11-29T15:36:02.950Z
2019-02-22T19:00:08.913Z
2019-02-22T19:00:08.913Z
Robin Schambach
<p>I have a matrix block that calls a category channel. The categories are nested three levels "deep" at times. I want to select first, second or third level links as needed.</p>

<p>When I use .last(), I can get the full url path to return. When I use .nth(n), I have to specify a value, which automatically limits the link path to that level of "deepness". </p>

<p>What can I do to <strong>get the .last() functionality, without using .last()?</strong></p>

<p>Note: <em>.last() will be deprecated going forward in Craft 3 and beyond</em>.</p>

<hr>

<categories><craft3>
Need .last() functionality for categories – .last() will be deprecated going forward
# Need .last() functionality for categories – .last() will be deprecated going forward

(Asked by: username_0 on 2017-11-29)

I have a matrix block that calls a category channel. The categories are nested three levels "deep" at times. I want to select first, second or third level links as needed.

When I use .last(), I can get the full url path to return. When I use .nth(n), I have to specify a value, which automatically limits the link path to that level of "deepness".

What can I do to **get the .last() functionality, without using .last()?**

Note: *.last() will be deprecated going forward in Craft 3 and beyond*.

---

**Tags:** categories, craft3


---

## 1 answers

### Answer by username_1 on 2017-11-29. Score: 7 | Accepted answer

If you are not going to update your current project to Craft 3 (which will break nearly all your templates and all plugins anyway) you don't need to bother about that message. This is only for Craft 3 and not for Craft 2.
Otherwise looking in the docs might be a good idea. You can do
{% set query = craft.entries().section('news') %}
{% set total = query.count() %}
{% set last = query.nth(total - 1) %}

or 
{% set oldest = craft.entries()
    .section('news')
    .inReverse()
    .one() 
%}

> **Comments:**
> **username_0**: So I am working in Craft 3 already and that link to the docs is very useful. I implemented `nth(query.count() - 1)` and it worked great. Thank you.  
> **username_2**: That docs link is now dead. This [one](https://github.com/craftcms/docs/blob/341b0d451507944dea8ba4bbefadce5a7298315d/en/changes-in-craft-3.md#last)  might be comparable. It also suggests: In most cases you can replace calls to `.last()` with `.inReverse().one()`  
> **username_3**: @username_2 your link is now dead as well. Any updated?  
> **username_2**: At this point, I'd say go to [https://docs.craftcms.com/v3/](https://docs.craftcms.com/v3/) and search for inReverse  

---

