# Counting Draft Page Children in a Page Model

**URL:** <https://forum.getkirby.com/t/counting-draft-page-children-in-a-page-model/34138>\
**Category:** Questions\
**Tags:** v4\
**Created:** [May 24, 2025, 12:59am UTC](https://forum.getkirby.com/t/counting-draft-page-children-in-a-page-model/34138 "2025-05-24T00:59:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scottboms](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/scottboms/32/15709_2.png) [@scottboms](https://forum.getkirby.com/u/scottboms)\
**Post date:** [May 24, 2025, 12:59am UTC](https://forum.getkirby.com/t/counting-draft-page-children-in-a-page-model/34138/1 "2025-05-24T00:59:48Z")

</div>

I’m working on some page model functions to integrate to a stats section in the panel and am either doing something wrong or maybe have run into a limitation or bug. Wondering if anyone can set me straight on this:

I have a page model file `notes.php` and in it is two main functions:

```auto
<?php 
  // site/models/notes

  class NotesPage extends Page {
    // Get all Notes
    public function getAllNotes() {
      $published_notes = $this->children();
      return $published_notes;
    }

    // Count the total number of notes
    public function getAllNotesCount() {
      $all_notes = $this->getAllNotes()->count();
      return (int) $all_notes;
    }

    // Count the toal number of unpublished notes
    public function getUnpublishedNotesCount() {
      $unpublished_notes_count = $this->getAllNotes()->drafts()->count();
      return (int) $unpublished_notes_count;
    }
}

```

The first two functions work but the last to get a count of drafts does not. Is this not supported or am I doing something wrong?

```auto
info: '{{ site.page("notes").drafts.count }} drafts

```

I do know that the above line in a blueprint as part of a stats section does work, but maybe I’m mistakenly assuming the same query should work in a model context.

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [May 24, 2025, 5:38am UTC](https://forum.getkirby.com/t/counting-draft-page-children-in-a-page-model/34138/2 "2025-05-24T05:38:21Z")

</div>

You are indirectly calling `children()->drafts()`. It should be either `drafts` (which are children) or just `children`. In the second and third functions of your class, try `$this->drafts()` instead of `$this->getAllNotes()`.

> **[$page-\>drafts()](https://getkirby.com/docs/reference/objects/cms/page/drafts)**
>
> Returns all draft children

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [May 24, 2025, 6:05am UTC](https://forum.getkirby.com/t/counting-draft-page-children-in-a-page-model/34138/3 "2025-05-24T06:05:42Z")

</div>

```auto
$page->children()

```

Listed and unlisted (=published) child pages

```auto
$page->drafts()

```

Draft child pages

```auto
$page->childrenAndDrafts()

```

Both published and draft child pages
