<p>That is returning an <code>ElementQuery</code>. I'm assuming you only need to get the first category. You need to use <code>.one</code> to get the category element.</p>

<pre><code>{% for row in entry.matrixField.all() %}
    {{ row.matrixChild.one.slug }}
{% endfor %}
</code></pre>

<p>If you wish to display more than one category you can use a <code>{% nav %}</code> or <code>{% for %}</code> to loop through them. See the <a href="https://docs.craftcms.com/v3/categories-fields.html" rel="nofollow noreferrer">category docs</a>.</p>

CC BY-SA 4.0
2018-05-11T22:44:46.017Z
Thanks Simon!  I had a few of those fields empty and I got an error so I added {% if row.matrixChild.one|length %} around it and it works :)
Vin
CC BY-SA 4.0
2018-05-11T22:46:58.987Z
You're welcome. Adding `|length` is exactly what I would do too.
Simon Kuran
CC BY-SA 4.0
2018-05-11T21:38:08.207Z
2018-05-11T22:33:09.337Z
2018-05-11T22:33:09.337Z
Simon Kuran
<p>I am not sure why, but I cannot seem to get the short name/handle/slug of a matrix field that is a category field.  I need to get it's slug.</p>

<pre><code>{% for row in entry.matrixField %}

 {{ row.matrixChild.slug }}

{% endfor %}
</code></pre>

CC BY-SA 4.0
2018-05-11T22:29:00.203Z
Just a side note: looping through `Queries` is deprecated. You should take a look into your deprecator logs
Robin Schambach
<matrix><craft3><slug>
Matrix Field Slug Output
# Matrix Field Slug Output

(Asked by: username_0 on 2018-05-11)

I am not sure why, but I cannot seem to get the short name/handle/slug of a matrix field that is a category field.  I need to get it's slug.
{% for row in entry.matrixField %}

 {{ row.matrixChild.slug }}

{% endfor %}

**Tags:** matrix, craft3, slug
> **Comments:**
> **username_1**: Just a side note: looping through `Queries` is deprecated. You should take a look into your deprecator logs  

---

## 1 answers

### Answer by username_2 on 2018-05-11. Score: 2 | Accepted answer

That is returning an ElementQuery. I'm assuming you only need to get the first category. You need to use .one to get the category element.
{% for row in entry.matrixField.all() %}
    {{ row.matrixChild.one.slug }}
{% endfor %}

If you wish to display more than one category you can use a {% nav %} or {% for %} to loop through them. See the category docs.

> **Comments:**
> **username_0**: Thanks Simon!  I had a few of those fields empty and I got an error so I added {% if row.matrixChild.one|length %} around it and it works :)  
> **username_2**: You're welcome. Adding `|length` is exactly what I would do too.  

---

