Query TODOs with tags does not work

I was making a qeury that only shows TODOs within pages that has a property stat:: #private

#+BEGIN_QUERY

{
 :title [:h3 "private TODOs" ]
 :query [:find (pull ?b [*])
 :where
         [?b :block/page ?p]	
         (property ?b :stat "private")
         [?b :block/marker "TODO"]
 ]
}

#+END_QUERY

But it returns nothing. Where did I go wrong?

This is my sample page

But your line:

(property ?b :stat "private")
  • uses property instead of page-property
  • uses ?b instead of ?p

Try this line instead:

(page-property ?p :stat "private")
1 Like

Sorry for the late reply. So this is the modified query according to your suggestion -
(edit for direct reply)

#+BEGIN_QUERY
{ 
:title [:h3 "private TODOs" ] 
:query [
 :find (pull ?b [*])
 :where 
   [?b :block/page ?p] 
   (page-property ?p :stat "private") 
   [?b :block/marker "TODO"] 
 ]
}
#+END_QUERY

However it does not seem to grab the TODO block under the page. I’m sure there’re some of them. I’ve again added the page referenced as following. Are there any instructions I didnt follow?

  • Page properties should be in the first block of the page.
    • But currently your first block is Description, so your page has no properties.
    • If you move the properties to the first block, the query will work.
  • If you need to break that convention and use another block, try something like this:
    #+BEGIN_QUERY
    {
    :title [:h3 "private TODOs" ]
    :query [
      :find (pull ?b [*])
      :where
        [?pb :block/page ?p]
        (property ?pb :stat "private")
        [?b :block/page ?p]
        [?b :block/marker "TODO"]
      ]
    }
    #+END_QUERY
    
1 Like

Hi there I have a related question: I want to query the following:

All blocks with Todos wich contain [[Keyword 1]] (not scheduled) I can make a query which finds all not scheduled tasks which looks like this:

#+BEGIN_QUERY 
{ 
 :title [:h2 "not scheduled"]
:query 
[
:find (pull ?b [*] )
:where
[?b :block/marker ?marker]
[(contains? #{"TODO" "DOING"} ?marker)]
(not [?b :block/scheduled])

]
}
#+END_QUERY

but I still dont figure out how to add, that it should only take out the todos which contain [[ Keyword 1]]

due to this long tutorial ([https://mschmidtkorth.github.io/logseq-msk-docs/#/page/612beaec-f2e0-41eb-902c-924d30050263]) It should work with the following:

#+BEGIN_QUERY
{:title "Find tag: MyTag"
:query [:find (pull ?b [*])
            :where
              [?b :block/ref-pages ?p]
              [?p :block/name "MyTag"]
	       ]
}
#+END_QUERY

But even if I try this without the condition of scheduled/unscheduled - the code does not work. Does anybody have comments on this ?

I am lucky for help!

Best regards from germany

Chris

:block/name expects the name in lower-case format (i.e. keyword 1 or mytag). The original case is available with :block/original-name. If that doesn’t work, provide specific example of tag and tasks.