Fetch children of page ID

This one seems like it should be fairly simple but I’m once again missing a trick here.

I have a page which has some children. When I’m visiting the page in Frontity, I’d expect I would have access to the children to at least be able to get their IDs, but I’m not being given anything.

I understand there’s a include_children parameter but I’m not sure how to go about using it.

Here’s what I’m trying to do:

  1. Find the page ID (data.id returns this fine)
  2. Find child pages of this ID
  3. Loop through child pages and render a component, passing things like the title and featured image

The include_children parameter only applies to taxonomies.

The REST API for pages does not return any information regarding children, and as far as the documentation states is there no way to get it (see: Pages | REST API Handbook | WordPress Developer Resources).

You can get the parent ID, although that doesn’t help much.

So what you can do is doing a second fetch for all pages which have a parent (by ID):
/wp-json/wp/v2/pages?parent=<parent_id>

Thanks @Johan, this really pointed me in the right direction.

I ended up modifying a hook I wrote to also allow fetching pages by parent.

For those trying to do the same thing, it looks like this:

api.get({
  endpoint: 'pages',
  params: { _embed: true, include: id, parent },
})

Where id and parent are props passed to the hook. If looking for all children pages of a parent, leave id as null.