<p>Because <code>extraEntries</code> is not an array of elements but an object of type <code>EntryQuery</code> in order to fetch the entries you have to do</p>

<pre><code>{% set extraEntries = craft.entries.section('events').relatedTo(category).orderBy('startDate asc').offset(3).all() %}
</code></pre>

<p>It was actually the same in Craft 2 but the class had an <code>iterable</code> and <code>countable</code> interface, so when you do <code>|length</code> it actually does <code>.total()</code> (to execute the command and fetch the number of rows) These automatic mechanisms are removed/deprecated now thus you have to know what kind of object you use</p>

<p>When you take a look at your cp you'll see a bunch of deprecated warnings.</p>

<p>I suggest you to read the <a href="https://github.com/craftcms/docs/blob/v3/en/element-queries.md" rel="nofollow noreferrer">docs</a></p>

CC BY-SA 3.0
2018-04-24T15:56:38.203Z
2018-04-24T16:13:34.857Z
2018-04-24T16:13:34.857Z
Robin Schambach
<p>This code worked fine in Craft 2:</p>

<pre><code> {% set entries = craft.entries.section('events').relatedTo(category).orderBy('startDate asc').limit(3) %}
 {% set extraEntries = craft.entries.section('events').relatedTo(category).orderBy('startDate asc').offset(3) %}
 {% if extraEntries | length %}
    //do some stuff
 {% endif %}
</code></pre>

<p>In Craft 3, <code>{{ extraEntries | length }}</code> is giving a value a 1 even when there are no entries. For example, <code>{% for e in extraEntries %}&gt;&gt;&gt;{{e}}{%endfor%}</code> doesn't output anything. Any thoughts?</p>

<templating><craft3><elementquery>
Twig: length giving 1 on empty array?
# Twig: length giving 1 on empty array?

(Asked by: username_0 on 2018-04-24)

This code worked fine in Craft 2:
 {% set entries = craft.entries.section('events').relatedTo(category).orderBy('startDate asc').limit(3) %}
 {% set extraEntries = craft.entries.section('events').relatedTo(category).orderBy('startDate asc').offset(3) %}
 {% if extraEntries | length %}
    //do some stuff
 {% endif %}

In Craft 3, {{ extraEntries | length }} is giving a value a 1 even when there are no entries. For example, {% for e in extraEntries %}>>>{{e}}{%endfor%} doesn't output anything. Any thoughts?

**Tags:** templating, craft3, elementquery


---

## 1 answers

### Answer by username_1 on 2018-04-24. Score: 1 | Accepted answer

Because extraEntries is not an array of elements but an object of type EntryQuery in order to fetch the entries you have to do
{% set extraEntries = craft.entries.section('events').relatedTo(category).orderBy('startDate asc').offset(3).all() %}

It was actually the same in Craft 2 but the class had an iterable and countable interface, so when you do |length it actually does .total() (to execute the command and fetch the number of rows) These automatic mechanisms are removed/deprecated now thus you have to know what kind of object you use
When you take a look at your cp you'll see a bunch of deprecated warnings.
I suggest you to read the docs


---

