Find every page by tag

Sorry if this is a silly question but I seem to be having difficulty finding every single item on a site by tag. I’m trying the following:

$tags = param('tags');
$items = $site->pages()->children()->filterBy('tags', $tags, ',');

I have both Artist and Event blueprints that have a field like so:

tags:
    type: tags

For some reason, this only seems to return the Artist pages and nothing else, even when the tag is very clearly visible on an Event item.

Just curious if I am missing something obvious? Or is there something more complex at play due to how pages may be nested and so on?

Where do you use this code? What is your page structure like?

Apart from that, you should only filter if the the tags parameter exists:

$items = $site->pages()->children();
if ($tags = param('tags')) {
    $items = $items->filterBy('tags', $tags, ',');
}

$pages->children() only returns second level pages…

Ah yes regarding making sure the param exists.

I don’t know if this is a reasonable way to do it, but I had just made an unlisted page called tag and a corresponding tag.json.php template. Perhaps it could also just be defined in a custom route in config.php?

If I remove children(), nothing is returned.

The events are essentialy grandchildren so is it due to the hierarchy that they aren’t being picked up?

EDIT Ok, so there was indeed an obvious solution, to use $items = $site->index() instead.

My apologies, thanks for your help as always @texnixe