# Filtering by collection list, if its array

**URL:** <https://discourse.getcockpit.com/t/filtering-by-collection-list-if-its-array/948>\
**Category:** General\
**Created:** [July 28, 2019, 1:50pm UTC](https://discourse.getcockpit.com/t/filtering-by-collection-list-if-its-array/948 "2019-07-28T13:50:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![YuriiLeso](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/yuriileso/32/462_2.png) [@YuriiLeso](https://discourse.getcockpit.com/u/YuriiLeso)\
**Post date:** [July 28, 2019, 1:50pm UTC](https://discourse.getcockpit.com/t/filtering-by-collection-list-if-its-array/948/1 "2019-07-28T13:50:42Z")

</div>

Hi folks,  
Let’s say I have a posts collection.  
Post’s item looks like  
{  
title: ,  
date:   
…  
…  
category: [  
{…, display: \<CAT\_URL\>, …},  
{…, display: \<CAT\_URL\>, …},  
…  
]  
}

Categories is a collection link that can have one or many categories. (Category is also collection)

Now, I want to GET all posts that have `category.display = "CAT_1"`  
It doesn’t work to call `/api/collcetions/posts?filter[category.display]=CAT_1`.  
It works only if category is not array (multiply: false)

I did not find any info about it. So, could somebody recommend me how to filter by multip collection lists?  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![YuriiLeso](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/yuriileso/32/462_2.png) [@YuriiLeso](https://discourse.getcockpit.com/u/YuriiLeso)\
**Post date:** [July 28, 2019, 3:36pm UTC](https://discourse.getcockpit.com/t/filtering-by-collection-list-if-its-array/948/2 "2019-07-28T15:36:18Z")

</div>

I found the solution.  
Create /config/api/post.php  
\<?php

$cat = $this-\>param(‘cat’);  
$post = $this-\>param(‘post’);

if (!$cat || !$post) {  
echo “Not found post or cat params…”;  
return “Not found post or cat params…”;  
}

$entries = cockpit(‘collections’)-\>find(‘post’, [  
‘filter’ =\> function($document) use ($cat, $post) {  
if ($document[‘url’] === $post){  
foreach((array)$document[‘category’] as $item) {  
if ($item[‘display’] === $cat) return true;  
}  
}

```
    return false;
}

```

]);

return $entries;

and itwill be possible to get all posts in category $post with the post url $post by calling get request to `/api/post?token=<TOKEN>&cat=<CAT>&post=<POST>`  
But i need to “expand” collection links. I mean get full information about collection (not {\_id: , display: , …}

Have somebody ideas how to to it?
