- This is a block that is connected to [[Project A]].
- Here is a Task that is relevant to this project, but it's not directly tagged with :
- TODO Write Stuff down
- On the other hand here is a Task that is tagged with the project:
- TODO Do Stuff
- TODO And here is a unrelated Task that should not be found
I can’t figure out a query that finds TODO Write Stuff down and TODO Do Stuff - both Tasks are somehow connected to Project A or aren’t they?
- Meeting notes
- TODO aaaa
- bbbbb
- TODO ccccc
- dddddd
- TODO eeeee
- <query here - would return all three TODOs>
Ideally the query wouldn’t need to change depending on the title of the block (that way I can just paste in the query as part of my meeting template and see all the actions at the end of the meeting)
Would love any help you could provide!!
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.