SCHEDULED tasks with a tag in the parent

I have this in my notes:

- #inbox
  - TODO Task A: Include this task SCHEDULED: <2024-06-28 Fri>
  - TODO Task B: Don't include this task
- TODO Task C: include this task #inbox SCHEDULED: <2024-06-29 Fri>

How can I write an advanced query that:

  1. only retrieves tasks under the #inbox tag
  2. only returns tasks that have been scheduled?

I tried:

#+BEGIN_QUERY
   { :query [:find (pull ?b [* {:block/_parent ...}])
            :in $ ?date ?tag
            :where [?b :block/scheduled ?day]
                   [?p :block/name ?tag]
                   [?b :block/refs ?p]
                   [?b :block/marker ?marker]
                   [(contains? #{"TODO"} ?marker)]]
    :inputs [:today "inbox"]
    }
#+END_QUERY

But that doens’t work: the SCHEDULED is a part of the TODO block, while the #inbox is in its ancestor. The query above looks for both these attributes to belong to the same block, which is not what we want.

Thank you!

1 Like

If you want to get a tag/reference in either the same block or one of its ancestors, could simply replace :block/refs with :block/path-refs

2 Likes

Oh wow, that’s precisely what I neeed. Thank you a ton, most appreciated!

Is there documentation that might’ve helped me find this out and discover more attributes? Is there a database or block attributes schema list? I don’t seem to see a maintained one.

Thank you again!

  • The schema is here.
  • Also enable in Advanced Settings the Developer mode, to get the current attributes in the context-menu of blocks and pages.
1 Like

Perfect, thanks much!