<p>The reason <a href="http://buildwithcraft.com/docs/templating/craft.entries#limit"><code>limit()</code></a> isn't working is that is a method on the <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel"><code>ElementCriteriaModel</code></a> you get from <a href="http://buildwithcraft.com/docs/templating/craft.entries"><code>craft.entries</code></a>. </p>

<p>Because you're actually dealing with a standard array when you access <code>catEntries</code>, what you want instead is Twig's <a href="http://twig.sensiolabs.org/doc/filters/slice.html"><code>|slice(start, length)</code></a> filter:</p>

<pre><code>{% for entry in catEntries|slice(0, 4) %}

   // You'll only get four entries shown here

{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-11-28T20:52:28.480Z
Worth mentioning, there is a shorthand for the `slice` filter... `catEntries[0:4]`
Lindsey D
CC BY-SA 3.0
2014-12-04T02:46:08.743Z
This worked flawlessly. Now I'm wondering if there's a way to order the categories that are returned, entries can come in any order, but I'd like my categories to output in a particular one here?
brandongcarroll
CC BY-SA 3.0
2014-11-28T15:09:45.727Z
2014-11-28T15:09:45.727Z
Mike Pepper
<p>I'm wondering how I would go about limiting the number of results returned from a set using the group filter? I only want four to show, but using the <code>limit()</code> method seems to throw errors wherever I put it. Here's my template code:</p>

<pre><code>{% set entries = craft.entries.section('recipes').find() %}

{% for category, catEntries in entries | group('cuisineType.first().title') %}

    {% for entry in catEntries %}

       // I only want four entries shown here

    {% endfor %}

{% endfor %}
</code></pre>

<templating><filter><category><limit>
How to limit number of entries returned from a group filter?
# How to limit number of entries returned from a group filter?

(Asked by: username_0 on 2014-11-28)

I'm wondering how I would go about limiting the number of results returned from a set using the group filter? I only want four to show, but using the limit() method seems to throw errors wherever I put it. Here's my template code:
{% set entries = craft.entries.section('recipes').find() %}

{% for category, catEntries in entries | group('cuisineType.first().title') %}

    {% for entry in catEntries %}

       // I only want four entries shown here

    {% endfor %}

{% endfor %}

**Tags:** templating, filter, category, limit


---

## 1 answers

### Answer by username_1 on 2014-11-28. Score: 5

The reason limit() isn't working is that is a method on the ElementCriteriaModel you get from craft.entries. 
Because you're actually dealing with a standard array when you access catEntries, what you want instead is Twig's |slice(start, length) filter:
{% for entry in catEntries|slice(0, 4) %}

   // You'll only get four entries shown here

{% endfor %}

> **Comments:**
> **username_2**: Worth mentioning, there is a shorthand for the `slice` filter... `catEntries[0:4]`  
> **username_0**: This worked flawlessly. Now I'm wondering if there's a way to order the categories that are returned, entries can come in any order, but I'd like my categories to output in a particular one here?  

---

