# For a given node, is it possible to get all the child nodes?

**URL:** <https://org-roam.discourse.group/t/for-a-given-node-is-it-possible-to-get-all-the-child-nodes/2039>\
**Category:** How To\
**Created:** [September 16, 2021, 8:25pm UTC](https://org-roam.discourse.group/t/for-a-given-node-is-it-possible-to-get-all-the-child-nodes/2039 "2021-09-16T20:25:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arozbiz](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@arozbiz](https://org-roam.discourse.group/u/arozbiz)\
**Post date:** [September 16, 2021, 8:25pm UTC](https://org-roam.discourse.group/t/for-a-given-node-is-it-possible-to-get-all-the-child-nodes/2039/1 "2021-09-16T20:25:35Z")

</div>

I have written some code that, in the org-roam buffer, displays backlinks not just to a file, but to any nodes in that file. But given how the org-roam database works—listing, for every node, its associated files—this is limited to calling the org-roam buffer on a file-level node, not any children nodes. Is there a way to generate, for any node, its child nodes? I think this discussion is [related](https://org-roam.discourse.group/t/package-release-org-roam-ui/1871/18): has any progress been made on this in org-roam?

For those who are interested, the code I’ve written to generate the child backlinks is this:

```auto
(defun azr/org-roam-get-child-nodes (node)
  "Get list of child nodes of NODE, if NODE is a file."
  (unless (= 1 (org-roam-node-point node))
    (error "NODE is not a file."))
  (let ((file (org-roam-node-file node)))
    (->> (org-roam-node-list)
	 (-filter (lambda (elt) (equal file (org-roam-node-file elt))))
	 (-filter (lambda (elt) (/= 1 (org-roam-node-point elt)))))))

(defun azr/org-roam-child-backlinks-section (node)
  "Like org-roam-backlinks-section but for backlinks to children nodes, if NODE is a file."
  (when-let ((backlinks (seq-sort #'org-roam-backlinks-sort (-flatten-n 1 (mapcar #'org-roam-backlinks-get (azr/org-roam-get-child-nodes node))))))
    (magit-insert-section (org-roam-backlinks)
      (magit-insert-heading "Backlinks (children):")
      (dolist (backlink backlinks)
        (org-roam-node-insert-section
         :source-node (org-roam-backlink-source-node backlink)
         :point (org-roam-backlink-point backlink)
         :properties (org-roam-backlink-properties backlink)))
      (insert ?\n))))

(setq org-roam-mode-section-functions
      '(org-roam-backlinks-section
	azr/org-roam-child-backlinks-section
	org-roam-reflinks-section))

```

It looks like this:

 ![image](https://global.discourse-cdn.com/free1/uploads/orgroam/original/1X/34299fa1d7899c46362153d18774ec4a46ddf2bd.png)
