Query for tagged items under parent block?

Taking meeting notes in the journal, I have a section for meetings and then a block under that for each meeting. Then I zoom into that meeting’s block to take notes.

  • Meeting with Group A
    • Note 1
    • Note 2
      • Note 2 sub note #action
    • Note 3
    • Note 4 #action
    • {{query (and (parent_block == this.parent) (tagged action))}}

I want to be able to insert something like that last line (likely via templates) and have it list the Note 2 sub note and Note 4 blocks (and their children). It should not return the actions from other meeting blocks.

Never mind the horribly butchered query syntax, just trying to get the concept out. Since I’d be templating it, I wouldn’t mind it being an advanced query if that’s what’s needed.

its not possible to query block base on parent of block that contain query string.

Ok so what if I want to query all actions under some other tag?

[[Tag1]]
 - Note
 - Note #action
 - Note

Now somewhere else, I want to query all #action under Tag1.

Is that possible?
EDIT: I figured out this is possible, it’s a simple query, mine was going wrong because of escape characters (I had an \ in the tag and it needed to be escaped \\, ctrl-shift-i is your friend).
{{query (and [[Action]] [[Tag1]])}}

Has my original question become possible in the last few months?

1 Like

I have similar interest in querying only tags under a parent block, if this could be implemented.
Like in current page we have 2 cases where same tag is used but only want to query 1 case with tag
Rob #project
–todo something
Ralph #project
–todo anything

Query only todo anything under Ralph, though same tag is used elsewhere on same page

This is now actually possible with advanced queries!

#+BEGIN_QUERY
{:title [:b "Action items"]
 :query [:find (pull ?b [*])
  :in $ ?parent %
  :where
   [?p :block/name "action"] ;lower-case page name
   [?b :block/refs ?p]
   (check-parent ?b ?parent)
 ]
 :rules [
   [(check-parent ?b ?parent)
     [?b :block/parent ?parent]
   ]
   [(check-parent ?b ?parent)
     [?b :block/parent ?c]
     (check-parent ?c ?parent)
   ]
 ]
 :group-by-page? false
 :breadcrumb-show? false
 :inputs [:parent-block]
}
#+END_QUERY

3 Likes

@Siferiax I’ve been trying to figure out how to do just this for HOURS and finally stumbled across this comment. I’m still trying to wrap my head around datalog syntax but it seems like the rule you’ve added does a sort of recursive search to match the parent block? Anyway, it works perfectly, thank you so much! :slight_smile:

1 Like

Yes, that’s exactly what it does :slight_smile: