Filtering invisible pages Index Fields

I’m using the Kirby Index plugin and a custom filter to show Projects/Events that are in the past or future, I now need to filter on another condition, whether the page is visible or not. I am having trouble getting this to work, for ‘Upcoming Projects’ I want to show Projects that are in the future and visible and for ‘Past Projects’ I want to show Projects that are in the past and visible. When I add !$page->isVisible() Past Events start appearing in Upcoming and visa-versa as you can see in the screenshots.

<?php

class IndexFilter {
    static function upcomingdate($data) {
        foreach($data as $key => $item) {
            $page = page($item['uri']);
            if(strtotime($page->startdate()->value()) < time() and !$page->isVisible())  {
                unset($data[$key]);
            }
        }
        return $data;
    }
    static function pastdate($data) {
        foreach($data as $key => $item) {
            $page = page($item['uri']);
            if(strtotime($page->startdate()->value()) > time() and !$page->isVisible())  {
                unset($data[$key]);
            }
        }
        return $data;
    }
}

You have to combine the two conditions with an or operator

if(strtotime($page->startdate()->value()) < time() || $page->isInvisible())  {
1 Like