<p>Try changing this:</p>

<pre><code>{% set category = craft.categories.slug(slug) %}
</code></pre>

<p>to</p>

<pre><code>{% set category = craft.categories.slug(slug).first() %}
</code></pre>

CC BY-SA 3.0
2017-04-17T19:06:41.973Z
Brad, you nailed it. I still don't understand why you have to explicitly mention `.first()` since there is only one object that is returned.
hvs
CC BY-SA 3.0
2017-04-17T20:42:52.587Z
Slugs are not unique, ids are, so there is a chance you could have more than one category being returned. Don't quote me on that, but just remember to use first()
Brad
CC BY-SA 3.0
2017-04-17T18:45:58.613Z
2017-04-17T18:45:58.613Z
Brad
<pre><code>{% set slug = craft.request.getParam('s') %}

{% if slug | length %}
    {% set category = craft.categories.slug(slug) %}
    {% set faqs = craft.entries.section('faq').order('title').limit(null) %}

    &lt;h3&gt;{{ category.title }}&lt;/h3&gt;

    &lt;ul class="no-bullet"&gt;
        {% for entry in faqs.relatedTo(category) %}
            {% if entry.level &gt;1 %} 
                &lt;li&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
            {% endif %}  
        {% endfor %}
    &lt;/ul&gt;
{% else %}
    &lt;h3&gt; No matching results found &lt;/h3&gt;
{% endif %} 
</code></pre>

<p>In the code above, I cannot get <code>{{ category.title }}</code> to display. It is empty. If I put <code>{{ category.slug }}</code> instead, it shows the correct value. The other items in unordered list are displaying perfectly. I am confused as to why the title is not showing    </p>

CC BY-SA 3.0
2017-04-17T18:44:54.760Z
If you simplify it to `{% set slug = craft.request.getParam('s') %}{% set category = craft.categories.slug(slug) %}{{ category.title }}` does it work?  Is this a multi-locale setup?
Brad Bell
<entries><category>
Cannot get category.title to show up
# Cannot get category.title to show up

(Asked by: username_0 on 2017-04-17)

{% set slug = craft.request.getParam('s') %}

{% if slug | length %}
    {% set category = craft.categories.slug(slug) %}
    {% set faqs = craft.entries.section('faq').order('title').limit(null) %}

    {{ category.title }}

    
        {% for entry in faqs.relatedTo(category) %}
            {% if entry.level >1 %} 
                {{ entry.title }}
            {% endif %}  
        {% endfor %}
    
{% else %}
     No matching results found 
{% endif %} 

In the code above, I cannot get {{ category.title }} to display. It is empty. If I put {{ category.slug }} instead, it shows the correct value. The other items in unordered list are displaying perfectly. I am confused as to why the title is not showing

**Tags:** entries, category
> **Comments:**
> **username_1**: If you simplify it to `{% set slug = craft.request.getParam('s') %}{% set category = craft.categories.slug(slug) %}{{ category.title }}` does it work?  Is this a multi-locale setup?  

---

## 1 answers

### Answer by username_2 on 2017-04-17. Score: 1 | Accepted answer

Try changing this:
{% set category = craft.categories.slug(slug) %}

to
{% set category = craft.categories.slug(slug).first() %}

> **Comments:**
> **username_0**: Brad, you nailed it. I still don't understand why you have to explicitly mention `.first()` since there is only one object that is returned.  
> **username_2**: Slugs are not unique, ids are, so there is a chance you could have more than one category being returned. Don't quote me on that, but just remember to use first()  

---

