Call to a member function children() on null

I really don’t get whats happening here since i use it just like that on other sites and it is working fine. Also it already worked on the site before and now the simplest line of kirby code is an “Call to a member function “whatever i use”() on null”

so this is just an example. Almost as if something broke in some other kirby settings on this very site? or got the “find()” function removed?

  <?php foreach($site->find('Projects')->children() as $projects): ?>
      <a class="project" href="<?= $projects->url() ?>"><h3><?= $projects->title() ?></h3></a>
  <?php endforeach ?>

Thanks again for your help :woozy_face:

The error message mean that


doesn’t return a page object, but null. So the page doesn’t exist. Probably just a problem with your uppercase P, try projects instead.

If there is a chance that the page is renamed or deleted at a later point in time and to prevent such errors, it is usually best practice to check if an object (in this case the page) exists before you call a member method (children()):

<?php if ($p = $site->find('Projects')) {
  foreach ($p->children() as $project): ?>
      <a class="project" href="<?= $project->url() ?>"><h3><?= $project->title() ?></h3></a>
<?php endforeach ?>

The pages i wanted to grab were drafts…
Thanks :slight_smile: