<p>This should do the trick:</p>

<pre><code>'criteria' =&gt; [
    'section' =&gt; 'trucks',
    'limit'   =&gt; 10,
    'order'   =&gt; 'title asc',
]
</code></pre>

<p>The <a href="https://craftcms.com/docs/templating/elementcriteriamodel" rel="nofollow noreferrer">Element Criteria Model documentation</a> has more information about setting criteria.</p>

<h3>Update for Craft 3.x*</h3>

<pre><code>The “order” element query param has been deprecated. Use “orderBy” instead.
</code></pre>

<p>* Craft v3.0.11 reports this in the <code>/admin</code> under <code>deprecation errors</code></p>

CC BY-SA 3.0
2017-04-19T19:00:18.990Z
Ah that did the trick. I tried that but not from WITHIN criteria, only after criteria.
Noah Yamen
CC BY-SA 3.0
2017-04-19T19:01:22.850Z
Is there a means to change the sort via the api, versus doing it on the front-end?
Noah Yamen
CC BY-SA 3.0
2017-04-19T19:05:10.373Z
Updated my answer with an "order" parameter.
Stephen Lewis
CC BY-SA 4.0
2017-04-19T17:20:10.823Z
2018-06-16T17:47:12.507Z
2018-06-16T17:47:12.507Z
Stephen Lewis
<p>Just setting the limit property doesn’t do the trick alone, you need to deactivate pagination, too:</p>

<pre><code>'criteria' =&gt; [
    'section' =&gt; 'trucks',
    'limit'   =&gt; 10,
    'orderBy'   =&gt; 'title asc',
],
'paginate' =&gt; false,
</code></pre>

CC BY-SA 4.0
2019-11-27T21:15:38.617Z
2019-11-27T21:15:38.617Z
medoingthings
<p>Currently collaborating on a site with another developer, which is using ElementAPI pretty heavily for content delivery. </p>

<p>Is there a way to limit the number of returns on any given json feed? Say; only return the 10 most recent entries in any given channel? Or order the returned data by a specified field asc/desc?</p>

<p>A sample code: </p>

<pre><code>'trucks.json' =&gt; [
  'elementType' =&gt; 'Entry',
  'criteria' =&gt; ['section' =&gt; 'trucks'],
  'paginate' =&gt; false,
  'transformer' =&gt; function(EntryModel $entry) {
    return [
      (int)$entry-&gt;id,
      $entry-&gt;manufacturer,
</code></pre>

<plugin-elementapi><order><limit>
ElementAPI: How to order and/or limit results?
# ElementAPI: How to order and/or limit results?

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

Currently collaborating on a site with another developer, which is using ElementAPI pretty heavily for content delivery. 
Is there a way to limit the number of returns on any given json feed? Say; only return the 10 most recent entries in any given channel? Or order the returned data by a specified field asc/desc?
A sample code: 
'trucks.json' => [
  'elementType' => 'Entry',
  'criteria' => ['section' => 'trucks'],
  'paginate' => false,
  'transformer' => function(EntryModel $entry) {
    return [
      (int)$entry->id,
      $entry->manufacturer,

**Tags:** plugin-elementapi, order, limit


---

## 2 answers

### Answer by username_1 on 2017-04-19. Score: 2 | Accepted answer

This should do the trick:
'criteria' => [
    'section' => 'trucks',
    'limit'   => 10,
    'order'   => 'title asc',
]

The Element Criteria Model documentation has more information about setting criteria.
Update for Craft 3.x*
The “order” element query param has been deprecated. Use “orderBy” instead.

* Craft v3.0.11 reports this in the /admin under deprecation errors

> **Comments:**
> **username_0**: Ah that did the trick. I tried that but not from WITHIN criteria, only after criteria.  
> **username_0**: Is there a means to change the sort via the api, versus doing it on the front-end?  
> **username_1**: Updated my answer with an "order" parameter.  

---

### Answer by username_2 on 2019-11-27. Score: 3

Just setting the limit property doesn’t do the trick alone, you need to deactivate pagination, too:
'criteria' => [
    'section' => 'trucks',
    'limit'   => 10,
    'orderBy'   => 'title asc',
],
'paginate' => false,


---

