Its possible to group queries by page references?

Hi, I’m looking for a task querie that groups the result by page references. This is not enter in every page and look for tasks related, this is about look at all tags at once and see it grouped by references. Is this possible?

Unfortunately I don’t think in the way you intend.
It’s possible to group by page, but this refers to the page the task is on. This is your default query result.

So the only thing left is a sort by reference.
Something I happen to have made today for myself :wink:

This gets all pages with a certain tag and then all tasks (TODO) that references those pages.
In the result-transform I put that reference in a block property and sort on it.
If you need I can adjust this for your purpose, if you don’t know how.

{:title [:h4 "✅ Taakjes"]
 :query [:find ?act (pull ?b [*])
  :keys gebied taak
   [?t :block/name "gebieden"]
   [?a :block/tags ?t]
   [?b :block/refs ?a]
   [?a :block/original-name ?act]
   [?b :block/marker "TODO"]
 :result-transform (fn [res] 
  (sort-by (fn [s] (get-in s [:block/properties :gebied])) < (map (fn [m] 
     (update (:taak m) :block/properties 
         (fn [u] (assoc u :gebied (get-in m [:gebied]))
  ) res))
 :group-by-page? false
 :breadcrumb-show? false
1 Like

Thank you very much, I will give it a try!

1 Like

Should I only replace the word “gebieden” with the tag of the pages i’m looking for? Or do I need to do something with the keys?


Yes, if you only replace that then the query already works.
Of course it does depend on your exact page structure.

This assumes:

Page with tags:: gebieden
Block that references that page and has marker TODO
This gives back the block and associates the referenced page to it.

So only “gebieden” is the static part, the rest is dynamic.

Thanks for your query example!

Do you know if it is possible to group the results by a property of the blocks?

Same answer as I gave earlier. Only in terms of sorting by it.