I’m trying to develop an advanced query that shows all pages with a value for the “status” property.
This is the simple query that works: {{query (page-property :status)}}
This is my attempt at the advanced query:
#+BEGIN_QUERY
{:title [:h3 "📊 Projects"]
:query [:find (pull ?p [*])
:where
[?p :block/properties ?prop]
[(get ?prop :status) ?status]
[(= ?status "[[IN-PROGRESS]]")]
[(= ?status "[[WAITING]]")]
[(= ?status "[[LATER]]")]
[(= ?status "[[BACKLOG]]")]
]
:view (fn [result] (for [r result] [:div [:a.tag.mr-1 {:href (str "#/page/" (clojure.string/replace r "/" "%2F") )} r ] ] ) )
}
#+END_QUERY
Any help would be appreciated!
1 Like
Thanks for clarifying. Ideally, I’d like to have an advanced query that shows all blocks with status as well as an advanced query for each status. I removed the lines to check for value and the value strings, and I get this error:
query-properties:: [:page :block]
#+BEGIN_QUERY
{:title [:h3 "📊 Projects"]
:query [:find (pull ?p [*])
:where
[?p :block/properties ?prop]
[(get ?prop :status) ?status]
]
:view (fn [result] (for [r result] [:div [:a.tag.mr-1 {:href (str "#/page/" (clojure.string/replace r "/" "%2F") )} r ] ] ) )
}
#+END_QUERY
Your :view
fails because it is fed blocks, while it expects strings.
- Replace
(pull ?p [*])
with a simple string variable, e.g. ?name
- Read the string with a line, e.g.
[?p :block/original-name ?name]
Thanks. I copied the view from another query, not realizing the mismatch, and I don’t need that view so I removed it.
For the query, I used this site to revise it: Logseq Query Builder
Example below. I have queries for each status, and just change out the title and final line.
Thanks for your help!
#+BEGIN_QUERY
{
:title [:h3 "🚧 Waiting"]
;; ---- Get every block into variable ?block
:query [:find (pull ?block [*])
;; ---- filter command
:where
;; ---- get page name (lowercase) from the special page block into variable ?pagename
[?block :block/name ?pagename]
;; ---- Select if block is a special page blockand has a single property (arg1) with value arg2
(page-property ?block :status "WAITING")
]
}
#+END_QUERY