Query to produce events in chronological order for current page only

Hi

I have a search query which will pull up scheduled events in chronological order:

#+BEGIN_QUERY
	{:title [:h3 "Scheduled events - next 1000 days"] 
     :query [:find (pull ?block [*])
          :in $ ?start ?next
          :where
          (or
            [?block :block/scheduled ?d]
            [?block :block/deadline ?d])
          [(>= ?d ?start)]
          [(<= ?d ?next)]]
        :result-transform (fn [result]
                            (sort-by (fn [d]
                                       (get d :block/scheduled) (get d :block/scheduled) ) result))
  :inputs [:8d-after :1000d-after]
  :collapsed? false}
#+END_QUERY

I am trying to manipulate this query so that it only shows scheduled events tagged with the name of the current page.

Here is my first attempt, but it doesn’t do what it’s supposed to do

#+BEGIN_QUERY
	{:title [:h3 "Scheduled events over next 1000 days tagged with current page"] 
     :query [:find (pull ?block [*])
          :in $ ?start ?next ?current-page
          :where
          [?p :block/name ?current-page]
          (or
            [?block :block/scheduled ?d]
            [?block :block/deadline ?d]
          )
          [(>= ?d ?start)]
          [(<= ?d ?next)]]
        :result-transform (fn [result]
                            (sort-by (fn [d]
                                       (get d :block/scheduled) (get d :block/scheduled) ) result))
  :inputs [:0d-after :1000d-after :current-page]
  :collapsed? false}
#+END_QUERY

It pulls up non-scheduled events, and events which are not tagged with current page. Does anyone know where I have gone wrong?

Ta

My guess on what’s wrong

you did not state how ?p relates to ?block.

Possible solution

Add [?block :block/path-refs ?p], this will make sure that ?block tags ?current-page.

Does it now work as intended? (sorry, don’t have the time right now to test it myself :frowning: )

1 Like

Many thanks. I have placed your suggestion just below the “where” statement, and it works a treat!!

1 Like