Filter by multiple related subpages

That’s the wrong way round. You need to check if the the filter collection has the child:

<?php  $allUsedCategories = $allUsedCategories->filter(fn ($child) => $filter->has($child)); ?>

On a side note, this if statement doesn’t make sense, you need a comparison here, not an assignment:

<?php if ($rubrikcheck === true): ?>

And the two statements can be combined into one. anyway:

<?php if ($rubrikcheck === true && $articles->count()): ?>

Thanks for helping out. I ended up using the $pages->intersection() method for the last step.

<!-- Filter by Block again -->
<?php $allUsedCategories = $allUsedCategories->intersection($filter); ?>