# Check if blog posts exist

**URL:** <https://forum.getkirby.com/t/check-if-blog-posts-exist/19607>\
**Category:** Questions\
**Tags:** v3\
**Created:** [October 2, 2020, 9:32am UTC](https://forum.getkirby.com/t/check-if-blog-posts-exist/19607 "2020-10-02T09:32:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![flobin](https://avatars.discourse-cdn.com/v4/letter/f/dec6dc/32.png) [@flobin](https://forum.getkirby.com/u/flobin)\
**Post date:** [October 2, 2020, 9:32am UTC](https://forum.getkirby.com/t/check-if-blog-posts-exist/19607/1 "2020-10-02T09:32:15Z")

</div>

Underneath project pages I would like to display related news items. I would only like to show this snippet if related news items actually exist. So I am filtering for them like this:

```
<?php $posts = page('home')->children()->visible()->filterBy('project', $pageProject)->flip()->limit(4);
if (!empty($posts)): ?>

```

After this, I create the html for showing these items.

However, the second line in my code doesn’t seem to work, as it always shows the related news bit. It works fine for project which have related news items, by the way.

[This is the full snippet](https://gist.github.com/Flobin/aee78cc2b0149ad3c4ff7e0dae6cfd0b).

How do I properly check if the news items exist?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 2, 2020, 9:35am UTC](https://forum.getkirby.com/t/check-if-blog-posts-exist/19607/2 "2020-10-02T09:35:49Z")

</div>

```auto
<?php $posts = page('home')->children()->visible()->filterBy('project', $pageProject)->flip()->limit(4);
if ( $posts->isNotEmpty() ): ?>

```

PHP’s `empty()` checks if a variable is empty, but in case of a collection without elements, the variable is not empty, because it contains the object.

---

<div class="post-metadata">

**Author:** ![flobin](https://avatars.discourse-cdn.com/v4/letter/f/dec6dc/32.png) [@flobin](https://forum.getkirby.com/u/flobin)\
**Post date:** [October 2, 2020, 9:37am UTC](https://forum.getkirby.com/t/check-if-blog-posts-exist/19607/3 "2020-10-02T09:37:46Z")

</div>

> [@texnixe](#):
>
> `if ( $posts->isNotEmpty() ):`

Thank you, this works!
