Query for Todos with page name and tag

Hi to all,

it may well be, that this question has been answered elsewhere (which I did not notice). I am having trouble to build a query that does the following:

  • Search for blocks which
  • contains a page name like [[@MN]] (for My Name) AND
  • contains the tag #talk AND
  • is an item with status TODO

So far I used the query builder (I must admit that this topic is still a closed book to me) and came up with the following query:

#+BEGIN_QUERY
{
:title [:u "My NM-Query"]
:query [:find (pull ?block [*])
:where
[?block :block/content ?blockcontent]
[?block :block/page ?page]
[?page :block/name ?pagename]
[?block :block/path-refs [:block/name "@mn"]]
(page-ref ?block "talk")
]
}
#+END_QUERY

Looking for open TODOs is a thing I have not yet been able to integrate.

Looing for page name AND tag works in most cases. Sometimes it shows blocks which seem to have nothing to do with the query resp. do not contain either page name or tag.

I’d be grateful for any hints how I could do this.

Check out this thread, hopefully that will provide your answer.

1 Like

Hi @Siferiax,

thanks, I have a 2/3 solution with your Task that have specific page reference. Where I do not succeed is to add a search for a specific tag:

#+BEGIN_QUERY
{:title [:h3 "Find TODOs with '@mn' AND '#talk'" ]
 :query [:find (pull ?b [*])
    :where
      [?p :block/name "@mn"] ; name is always lowercase
      [?b :block/refs ?p] ; this block references ?p as oppose to being on ?p through :block/page.
      [?b :block/marker "TODO"]
      [?t :block/name "talk"] ; where/how to I use the "(and ...)"
 ]
}
#+END_QUERY

This works but does not link the 3 criteria via AND so some TODOs contain “talk” others only “mn” not.

In any case, thanks a lot for you help!

And is always used between statements.
However your query does not link ?b and ?t currently.
So you will need a [?b :block/refs ?t] statement after [?t :block/name "talk"].

1 Like

Thanks very, very much! That did the trick.