Exclude Tasks from a certain pages

Apologies if you’ve seen this question before. I was doing reasonably okay with queries until I get this problem.

I have a “catch-all tasks” query, but its grabbing tasks I have placed in my templates. Not ideal.

Is there a way to exclude all tasks which have a certain tag, or linked to a page? I found the “not=” operator in datalog docs but it doesnt seem straight forward.

Any suggestions appreciated.

replace “tag” with your tag/link that you want to exclude. use lower-cased text.

#+BEGIN_QUERY
{
 :query [:find (pull ?b [*])
         :where
         (task ?b #{"TODO"})
         [?ref :block/name "tag"]
         (not [?b :block/refs ?ref])
       ]
}
#+END_QUERY