<p>Your Categories field (<code>entry.chooseLocation</code>) is an <strong>Element Criteria Model</strong>. It's exactly the same as if you'd done something like this...</p>

<pre><code>craft.categories.group('myGroup')
</code></pre>

<p>The Element Criteria Model (ECM) is an important concept in Craft, because it's the driver for <em>most</em> content handling. Once you've got a bearing on what the ECM is, you can use it fairly consistently.</p>

<p>For example, just like <code>craft.entries</code>, you can apply <code>.find</code>, <code>.first</code>, and <a href="https://craftcms.stackexchange.com/a/16070/45">other methods</a> to retrieve a specific subset of elements. And depending on the element type, you can chain other filtering methods in between...</p>

<pre><code>craft.categories.group('myGroup').limit(3).find()
</code></pre>

<p>Returning to your question, <code>entry.chooseLocation</code> will be an ECM for Categories. So it's just a matter of filtering it appropriately.</p>

<pre><code>{% for category in entry.chooseLocation.level(2).find() %}
</code></pre>

<p>Here is the <a href="https://craftcms.com/docs/templating/craft.categories" rel="nofollow noreferrer">full list of filtering options</a> you can use on a Categories ECM.</p>

CC BY-SA 3.0
2016-09-22T19:26:40.913Z
Hmmm I may also have something else buggy going on... When I update my code to include `.level(2).find()` like you show above, I get nothing, when I change it to `.level(1).find()` it works and shows the parent. I double checked my entries I'm testing against, and I've selected the child category and saved, but when I look at the `chooseLocation` field, it shows the parent category as the chosen option. Screenshots - select the child category: https://goo.gl/RDjCzj and what shows after selecting the child category: https://goo.gl/HRJssb. I'm not sure if that is normal behavior or not though.
ByteMyPixel
CC BY-SA 3.0
2016-09-22T19:29:02.077Z
Ah, I think I see what's happening... When you created the field, did you limit the maximum to `1`? That actually prevents child categories from being selected (since the parent will _always_ be selected).
Lindsey D
CC BY-SA 3.0
2016-09-22T19:35:41.453Z
Yes, that was it! I had the limit set to 1 :/  I removed that, reselected the child category for each entry, and now `{% for category in entry.chooseLocation.level(2).find() %}` works perfectly :)
ByteMyPixel
CC BY-SA 3.0
2016-09-22T19:36:34.357Z
Great! It's a quirky limitation, and ends up being a "gotcha" for a lot of people. :)
Lindsey D
CC BY-SA 3.0
2016-09-22T18:43:45.063Z
2016-09-22T18:43:45.063Z
2017-04-13T12:51:00.160Z
Lindsey D
<p>I have a category page that lists all of the entries related to that category. And then I want to display the selected child category for the entry... in brief like so:</p>

<p><strong>Entry Title 1</strong><br>
<em>Entry 1's Child-Category</em></p>

<p><strong>Entry Title 2</strong><br>
<em>Entry 2's Child-Category</em></p>

<p><strong>Entry Title 3</strong><br>
<em>Entry 3's Child-Category</em></p>

<p>My category field handle is <code>chooseLocation</code></p>

<p>Here is what I have in my template:
<a href="https://craftcms.stackexchange.com/questions/16328/how-do-i-output-all-field-values-from-a-category-on-the-current-entry">(snippet taken from here)</a></p>

<pre><code>{% for entry in entries %}
    {% if entry.chooseLocation | length %}
    {% for category in entry.chooseLocation %}
         &lt;a href="/location/{{ category.slug }}"&gt;{{ category }}&lt;/a&gt;
            {% if not loop.last %}, {% endif %}
        {% endfor %}
    {% endif %}
{% endfor %}
</code></pre>

<p>The problem is, this get's the parent category (which is the category page we're on) but not the <em>child</em> category. I need to show just the child category and not the parent.  </p>

<p>I've looked through the docs but I can't find anything on how to do this.</p>

<categories><children>
How can I get an entry's child category, and not the parent category?
# How can I get an entry's child category, and not the parent category?

(Asked by: username_0 on 2016-09-22)

I have a category page that lists all of the entries related to that category. And then I want to display the selected child category for the entry... in brief like so:
Entry Title 1
Entry 1's Child-Category
Entry Title 2
Entry 2's Child-Category
Entry Title 3
Entry 3's Child-Category
My category field handle is chooseLocation
Here is what I have in my template:
(snippet taken from here)
{% for entry in entries %}
    {% if entry.chooseLocation | length %}
    {% for category in entry.chooseLocation %}
         {{ category }}
            {% if not loop.last %}, {% endif %}
        {% endfor %}
    {% endif %}
{% endfor %}

The problem is, this get's the parent category (which is the category page we're on) but not the child category. I need to show just the child category and not the parent.  
I've looked through the docs but I can't find anything on how to do this.

**Tags:** categories, children

---

## 1 answers

### Answer by username_1 on 2016-09-22. Score: 3 | Accepted answer

Your Categories field (entry.chooseLocation) is an Element Criteria Model. It's exactly the same as if you'd done something like this...
craft.categories.group('myGroup')

The Element Criteria Model (ECM) is an important concept in Craft, because it's the driver for most content handling. Once you've got a bearing on what the ECM is, you can use it fairly consistently.
For example, just like craft.entries, you can apply .find, .first, and other methods to retrieve a specific subset of elements. And depending on the element type, you can chain other filtering methods in between...
craft.categories.group('myGroup').limit(3).find()

Returning to your question, entry.chooseLocation will be an ECM for Categories. So it's just a matter of filtering it appropriately.
{% for category in entry.chooseLocation.level(2).find() %}

Here is the full list of filtering options you can use on a Categories ECM.

> **Comments:**
> **username_0**: Hmmm I may also have something else buggy going on... When I update my code to include `.level(2).find()` like you show above, I get nothing, when I change it to `.level(1).find()` it works and shows the parent. I double checked my entries I'm testing against, and I've selected the child category and saved, but when I look at the `chooseLocation` field, it shows the parent category as the chosen option. Screenshots - select the child category: https://goo.gl/RDjCzj and what shows after selecting the child category: https://goo.gl/HRJssb. I'm not sure if that is normal behavior or not though.  
> **username_1**: Ah, I think I see what's happening... When you created the field, did you limit the maximum to `1`? That actually prevents child categories from being selected (since the parent will _always_ be selected).  
> **username_0**: Yes, that was it! I had the limit set to 1 :/  I removed that, reselected the child category for each entry, and now `{% for category in entry.chooseLocation.level(2).find() %}` works perfectly :)  
> **username_1**: Great! It's a quirky limitation, and ends up being a "gotcha" for a lot of people. :)  

---

