Query: How to sort todos by page reference with certain tags (GTD)

Hi there,

I am using the GTD method to organize my tasks:
TODO [[projectname]] get milk #supermarket
TODO [[AnotherProject]] get oranges #supermarket
The page references the project which has a tags:: property “project” and the context is referenced by # with property “tags:: context”.
The tasks are created while journalling (basically the barebone gtd method).

On the “supermarket” page, I built a query that lists all todos in my graph with this tag.
→ When I am in the supermarket, i can see what i need to do “there” for all projects I am working on.
This also works for people, reocccuring meetings and so on.

Problem: How do I sort by page-ref that has the tag “project”? Sorting by page-ref alone does not work because a [[page]] and #page seems to be the same in queries.

#+BEGIN_QUERY
{:title "offene todos"
  :query [
    :find (pull ?b [* {:block/_parent ...}])
    :in $ ?current-page
    :where
      [?p :block/name ?current-page]
      [?b :block/path-refs ?p]
      [?b :block/marker ?marker]
      [(contains? #{"TODO"  "LATER" "WAITING"} ?marker)]]
  :inputs [:current-page]
  :result-transform 
    (fn [result]
      (sort-by 
        (fn [b] (get b :block/priority "Z"))
        (sort-by 
          (fn [b] (= (get b :block/marker) "TODO") ) 
          result)))
 :breadcrumb-show? false
}
#+END_QUERY

Basically I would like to sort-by the first page-ref whose name is not ?current-page or I introduce a new property type:: project which I would use. Problem is, that I can’t figure out the datalog syntax to group the todos by [[project]] , ideally usable in a template, so without defining the specific page.