# Filter by last date from structure

**URL:** <https://forum.getkirby.com/t/filter-by-last-date-from-structure/13134>\
**Category:** Questions\
**Tags:** v3\
**Created:** [March 1, 2019, 10:40am UTC](https://forum.getkirby.com/t/filter-by-last-date-from-structure/13134 "2019-03-01T10:40:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxlennarts](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@maxlennarts](https://forum.getkirby.com/u/maxlennarts)\
**Post date:** [March 1, 2019, 10:40am UTC](https://forum.getkirby.com/t/filter-by-last-date-from-structure/13134/1 "2019-03-01T10:40:48Z")

</div>

Trying to figure out how to filter from last date in structure field.  
Went trough some topics but im still not able to find it.

```
  playtime:
    label: playtime
    type: structure
    fields:
      title:
        label: Event title
        type: text
      eventdate:
        label: Event date
        type: date
      location:
        label: Event location
        type: text

  <?php

$items = page('archief')->children()->filter(function($child) {
$structure = $child->playtime()->toStructure();
return $structure->date('eventdate')->toDate() > time();
});

?>

```

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [March 1, 2019, 10:47am UTC](https://forum.getkirby.com/t/filter-by-last-date-from-structure/13134/2 "2019-03-01T10:47:40Z")

</div>

So you only want dates in the future, sorted by date?

---

<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:** [March 1, 2019, 10:51am UTC](https://forum.getkirby.com/t/filter-by-last-date-from-structure/13134/3 "2019-03-01T10:51:27Z")

</div>

Not tested, but something like this should work:

```auto
<?php
$items = page('archief')->children()->filter(function($child) {
  $structure = $child->playtime()->toStructure();
  return $structure->filter(function($item) {
    return $item->eventdate()->toDate() > time();
  });
});

```

---

<div class="post-metadata">

**Author:** ![maxlennarts](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@maxlennarts](https://forum.getkirby.com/u/maxlennarts)\
**Post date:** [March 1, 2019, 11:04am UTC](https://forum.getkirby.com/t/filter-by-last-date-from-structure/13134/4 "2019-03-01T11:04:47Z")

</div>

its now showing all the children, future and past. Even the ones that have no date attached yet in the field.

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [March 1, 2019, 11:11am UTC](https://forum.getkirby.com/t/filter-by-last-date-from-structure/13134/5 "2019-03-01T11:11:09Z")

</div>

Is this Kirby 2 or 3? Please change your post topic accordingly.

---

<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:** [March 1, 2019, 11:11am UTC](https://forum.getkirby.com/t/filter-by-last-date-from-structure/13134/6 "2019-03-01T11:11:50Z")

</div>

> [@texnixe](#):
>
> \<?php $items = page(‘archief’)-\>children()-\>filter(function($child) { $structure = $child-\>playtime()-\>toStructure(); return $structure-\>filter(function($item) { return $item-\>eventdate()-\>toDate() \> time(); }); });

Maybe we need a boolean here:

```auto
<?php
$items = page('archief')->children()->filter(function($child) {
  $structure = $child->playtime()->toStructure();
  return $structure->filter(function($item) {
    return $item->eventdate()->toDate() > time();
  })->count();
});

```

---

<div class="post-metadata">

**Author:** ![maxlennarts](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@maxlennarts](https://forum.getkirby.com/u/maxlennarts)\
**Post date:** [March 1, 2019, 11:15am UTC](https://forum.getkirby.com/t/filter-by-last-date-from-structure/13134/7 "2019-03-01T11:15:40Z")

</div>

Yes now it works! so adding the -\>count() did the trick?

Got to love the Kirby Team!  
Thanks for the patience with newbies!

---

<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:** [March 1, 2019, 11:19am UTC](https://forum.getkirby.com/t/filter-by-last-date-from-structure/13134/8 "2019-03-01T11:19:32Z")

</div>

> [@maxlennarts](#):
>
> so adding the -\>count() did the trick?

Yes, it returns false if the structure field doesn’t contain any items with an event date in the future.
