->visible() doesn't check parents/grandparents

using ->visible() doesn’t seem to check parents/grandparents… is there a tidy way to do this? I’m trying to get a filtered set of pages that match a particular tag and, of course, are visible but some of the pages are nested in invisible parent subfolders yet still get passed through. thanks.

That is certainly possible. Could you post your filter code please?

Thanks – it’s like this:
$works = $site->index()->visible()->filterBy(‘tags’, ‘stockroom’, ‘,’)->sortBy(‘prioirty’, ‘desc’);

Don’t know if there is an easier way to achieve this, but this should work:

$filtered = $site->index()->visible()->filterBy('tags', 'stockroom')->filter(function($child) {
      $countParents = $child->parents()->count();
      $countVisibleParents = $child->parents()->visible()->count();
      if($countParents == $countVisibleParents) {
        return $child;
      }
    });
1 Like