FInd nested TODOs

Since it was featured in Logseq Times, I’ll just add to this post to say I’m a dumdum and there is an attribute for this, making the query A LOT simpler!

This is for the query based on page reference, not the one based on parent blocks.

#+BEGIN_QUERY
{:title ["Query by page & alias"]
 :query [:find (pull ?b [*])
   :in $ ?page
   :where
     [?b :block/marker "TODO"]
     [?p :block/name ?page]
     (or-join [?b ?p]
       [?b :block/path-refs ?p]
       (and 
         [?p :block/alias ?a]
         [?b :block/path-refs ?a]
       )
     )
 ]
 :result-transform :sort-by-priority
 :table-view? false
 :inputs [:query-page] ; alternatively use the lower-case name of a page.
}
#+END_QUERY

This query uses :block/path-refs to find all references in all parent blocks, including the block itself.
As opposed to :block/refs which only looks at the references of the block itself.

2 Likes