<p>You can use <code>{{ craft.entries.section('whatever').total() }}</code> for that.</p>

CC BY-SA 3.0
2017-05-15T13:17:46.040Z
For some reason `.total()` is slower than `.limit(1) | length`, by ~10ms on average. And also this is only testing when there are 1 or 0 active entries.
peirix
CC BY-SA 3.0
2017-05-15T13:20:39.300Z
That's a cool tip. Did you compare it to Jeremy's suggestion?
Fred Carlsen
CC BY-SA 3.0
2017-05-16T14:09:39.880Z
Yeah, that was about the same as `.limit(1) | length`, so actually faster than `total()`
peirix
CC BY-SA 3.0
2017-05-12T09:12:40.023Z
2017-05-12T09:12:40.023Z
Fred Carlsen
<p>Not a definitive answer at all, but you could at least add a <code>.ids()</code> on that so it only retrieves the entry ids and not all the entry data...</p>

<pre><code>{% if craft.entries.section('whatever').ids() | length &gt; 0 %}
&lt;a href="www.com"&gt;Go here&lt;/a&gt;
{% endif %}
</code></pre>

CC BY-SA 3.0
2017-05-12T08:23:50.903Z
Would this be better than doing `.section().first.id`?
peirix
CC BY-SA 3.0
2017-05-16T09:27:30.943Z
`.section().first.id` will break if there is no ids.
Fred Carlsen
CC BY-SA 3.0
2017-05-12T08:21:44.457Z
2017-05-12T08:21:44.457Z
Jeremy Daalder
<p>Just wondering what the most efficient way to check whether a section has any entries or not. Based on this, I'm showing some content. The content doesn't take any information from the entries in the section, so it'll be a superfluous query no matter what.</p>

<p>For context, this is basically what it'll look like:</p>

<pre><code>{% if craft.entries.section('whatever') | length &gt; 0 %}
    &lt;a href="www.com"&gt;Go here&lt;/a&gt;
{% endif %}
</code></pre>

<entries><sections><query>
Most efficient way to check if a section has any active entries
# Most efficient way to check if a section has any active entries

(Asked by: username_0 on 2017-05-12)

Just wondering what the most efficient way to check whether a section has any entries or not. Based on this, I'm showing some content. The content doesn't take any information from the entries in the section, so it'll be a superfluous query no matter what.
For context, this is basically what it'll look like:
{% if craft.entries.section('whatever') | length > 0 %}
    Go here
{% endif %}

**Tags:** entries, sections, query


---

## 2 answers

### Answer by username_2 on 2017-05-12. Score: 4 | Accepted answer

Not a definitive answer at all, but you could at least add a .ids() on that so it only retrieves the entry ids and not all the entry data...
{% if craft.entries.section('whatever').ids() | length > 0 %}
Go here
{% endif %}

> **Comments:**
> **username_0**: Would this be better than doing `.section().first.id`?  
> **username_1**: `.section().first.id` will break if there is no ids.  

---

### Answer by username_1 on 2017-05-12. Score: 6

You can use `{{ craft.entries.section('whatever').total() }}` for that.

> **Comments:**
> **username_0**: For some reason `.total()` is slower than `.limit(1) | length`, by ~10ms on average. And also this is only testing when there are 1 or 0 active entries.  
> **username_1**: That's a cool tip. Did you compare it to Jeremy's suggestion?  
> **username_0**: Yeah, that was about the same as `.limit(1) | length`, so actually faster than `total()`  

---

