# Return the first article in an ordered category

**URL:** <https://discourse.cakephp.org/t/return-the-first-article-in-an-ordered-category/8553>\
**Category:** Need Help\
**Created:** [October 28, 2020, 12:28pm UTC](https://discourse.cakephp.org/t/return-the-first-article-in-an-ordered-category/8553 "2020-10-28T12:28:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![6120](https://avatars.discourse-cdn.com/v4/letter/6/278dde/32.png) [@6120](https://discourse.cakephp.org/u/6120)\
**Post date:** [October 28, 2020, 12:28pm UTC](https://discourse.cakephp.org/t/return-the-first-article-in-an-ordered-category/8553/1 "2020-10-28T12:28:12Z")

</div>

CakePHP 3.8  
I am trying to find the first article in each selected category in a cell  
In Categories table :

$this-\>hasOne(‘FirstArticle’, [  
‘className’ =\> ‘Articles’,  
‘foreignKey’ =\> ‘category\_id’,  
‘strategy’ =\> ‘select’,  
‘sort’ =\> [‘FirstArticle.sort’ =\> ‘ASC’]  
]);

in the display method of a cell :

$this-\>loadModel(‘Categories’);  
$query = $this-\>Categories-\>find()  
-\>select([‘Categories.id’, ‘Categories.name’])  
-\>where([‘Categories.id \>’ =\> 1, ‘Categories.sidebar’ =\> 1])  
-\>contain([  
‘FirstArticle’ =\> [‘fields’ =\> [‘FirstArticle.id’, ‘FirstArticle.category\_id’, ‘FirstArticle.name’, ‘FirstArticle.slug’, ‘FirstArticle.sort’]]  
])  
-\>order([‘Categories.lft’ =\> ‘ASC’])  
-\>limit(6)  
;

sort = name of a column in Articles table. In some categories, articles are ordered through this sort column.

This method returns an article ordered by categories order : I mean :  
first article of first category , second article of second category etc.  
This is not what I want.

Any idea ?
