List all child pages in the parent page

I would like to query a list of all children pages of the current page. I have used the below query from the following link, but the result includes the parent as well in the list. How can I only get the child pages?

I’m running this query in the “Parent” page

Below is an example page structure:

- Root
   - Parent
        - Child1
        - Child 2
#+BEGIN_QUERY
{ :title "Current Members"
  :query [:find (pull ?p [*])
                :in $ ?parent
                :where 
                [?p :block/name ?name]
                [(clojure.string/starts-with? ?name ?parent)]
                [(clojure.string/includes? ?name  "/")]]
  :inputs [:current-page] }
#+END_QUERY

my hunch is that I need to change the last function [(clojure.string/includes? ?name "/")]], because this is returning true for the “Parent” as well since its name is “Root/Parent”.

I tried this: [(clojure.string/includes? ?name (apply str [?parent "/" ]))]]

But I can’t seem to figure out the clojure syntax to write

1 Like

Suggestion for a completely different query :slight_smile:

#+BEGIN_QUERY
{:title "Current Members"
 :query [:find (pull ?p [*])
  :in $ ?current
  :where
   [?c :block/name ?current]
   [?p :block/namespace ?c]
 ]
 :inputs [:query-page]
}
#+END_QUERY

1 Like

How do I include all the sub-childs (if any) as well in this query? like below:

- Root
   - Parent
        - Child1
        - Child 2
            - Child 2.1

You may be looking for this:

[(str ?parent "/") ?ns]
[(clojure.string/includes? ?name ?ns)]