<p>When you're setting <code>section.links.limit(4)</code>, Craft will persist that limit in subsequent calls.</p>
<p>This was a change introduced in Craft 3, which you can read about <a href="https://docs.craftcms.com/v3/changes-in-craft-3.html#cloning-element-queries" rel="nofollow noreferrer">Changes in Craft 3 | Cloning Element Queries</a></p>
<hr />
<p>You have two options to resolve your issue:</p>
<p>Use <code>clone()</code> to create a new version of the <code>ElementCriteriaModel</code> for each time you use <code>section.links</code></p>
<pre><code>{% for mainLink in clone(section.links).limit(4).all() %}
{% endfor %}

{% for secondaryLink in clone(section.links).offset(4).all() %}
{% endfor %}
</code></pre>
<p>Or unset the limit your limit in the second for loop</p>
<pre><code>{% for mainLink in section.links.limit(4).all() %}
{% endfor %}

{% for secondaryLink in section.links.limit(null).offset(4).all() %}
{% endfor %}
</code></pre>

CC BY-SA 4.0
2020-07-01T10:31:35.690Z
2020-07-01T10:31:35.690Z
Joshua M
<p>Joshua M's answer explains why it's happening, but in terms of best practice, you'd be better off avoiding multiple roundtrips to the database by using Twig filters on a single result set. There are probably a few different ways, but here's one using <code>slice</code>:</p>
<pre><code>{% set allLinks = section.links.all() %}

{% for link in allLinks|slice(0, 3) %}
    {# iterate through the first 4 items #}
{% endfor %}

{% for link in allLinks|slice(3) %}
    {# iterate from the 4th item to the last #}
{% endfor %}
</code></pre>

CC BY-SA 4.0
2020-07-01T16:22:43.323Z
2020-07-01T16:22:43.323Z
James Smith
<p>If have this in a template:</p>
<pre><code>{% for mainLink in section.links.limit(4).all() %}
{% endfor %}

{% for secondaryLink in section.links.offset(4).all() %}
{% endfor %}
</code></pre>
<p>Which I thought would show the first four in the first list and however many from 5 onwards in the secondary list. But what's happening is that the second list is limiting the output to 4 as well. Why is that?</p>

<entries><query><limit>
Offset setting a limit?
# Offset setting a limit?

(Asked by: username_0 on 2020-07-01)

If have this in a template:
{% for mainLink in section.links.limit(4).all() %}
{% endfor %}

{% for secondaryLink in section.links.offset(4).all() %}
{% endfor %}

Which I thought would show the first four in the first list and however many from 5 onwards in the secondary list. But what's happening is that the second list is limiting the output to 4 as well. Why is that?

**Tags:** entries, query, limit

---

## 2 answers

### Answer by username_1 on 2020-07-01. Score: 3 | Accepted answer

When you're setting section.links.limit(4), Craft will persist that limit in subsequent calls.
This was a change introduced in Craft 3, which you can read about Changes in Craft 3 | Cloning Element Queries

You have two options to resolve your issue:
Use clone() to create a new version of the ElementCriteriaModel for each time you use section.links
{% for mainLink in clone(section.links).limit(4).all() %}
{% endfor %}

{% for secondaryLink in clone(section.links).offset(4).all() %}
{% endfor %}

Or unset the limit your limit in the second for loop
{% for mainLink in section.links.limit(4).all() %}
{% endfor %}

{% for secondaryLink in section.links.limit(null).offset(4).all() %}
{% endfor %}


---

### Answer by username_2 on 2020-07-01. Score: 3

Joshua M's answer explains why it's happening, but in terms of best practice, you'd be better off avoiding multiple roundtrips to the database by using Twig filters on a single result set. There are probably a few different ways, but here's one using slice:
{% set allLinks = section.links.all() %}

{% for link in allLinks|slice(0, 3) %}
    {# iterate through the first 4 items #}
{% endfor %}

{% for link in allLinks|slice(3) %}
    {# iterate from the 4th item to the last #}
{% endfor %}


---

