Random front page

I am updating the theme for Kirby 4. The shuffle function worked well with the selection of the respective children. Now I would like to shuffle all pages of the type work. What do I have to change here?

    [
      'pattern' => '/',
      'action'  => function() {
        return page('home/works')->children()->listed()->shuffle()->first();
      }
    ]

You could use ->template('yourTemplateTypeToFilterFor') after ->listed().

[
      'pattern' => '/',
      'action'  => function() {
        return page('home')->children()->template('work')->listed()->shuffle()->first();
      }
    ]

The page works collected all work pages. Now all pages are children of home. I hope this works!

Cannot it be shorter? Like this:

    [
      'pattern' => '/',
      'action'  => function() {
        return $page->template('work')->listed()->shuffle()->first();
      }
    ]

You cannot filter a single page, template() is a shortcut for filterBy('template', 'mytemplate')

Like this?

[
      'pattern' => '/',
      'action'  => function() {
        return $pages->template('work')->listed()->shuffle()->first();
      }
    ]

That would work if your pages with that template were on the first level. To get all pages with that template no matter where they are in the tree , you’d have to go via site()->index()

Please check the documentation to understand what the variables give you.