Advanced Queries, Show pages with both/multiple tags. Alternatively Show pages with a tag and a status

Hello everyone,

I would like to adapt the Logseq Documents example for querying for pages with a certain tag

{:title "All pages have a *programming* tag"
 :query [:find ?name
       :in $ ?tag
       :where
       [?t :block/name ?tag]
       [?p :block/tags ?t]
       [?p :block/name ?name]]
 :inputs ["programming"]
 :view (fn [result]
       [:div.flex.flex-col
        (for [page result]
          [:a {:href (str "#/page/" page)} (clojure.string/capitalize page)])])}
#+END_QUERY

Instead of having just the programming tag, I would like to refine the results to having 2 tags, “programming” and “priority”

Additionally I would like to know how I can use an advanced query for a page with the tag “programming” and status “ongoing”

Thank you in advance

I have been using the following query to perform a search against two sep tags:

#+BEGIN_QUERY
{:title [:h1 "Example"]
 :inputs ["programming" "priority"]
 :query [:find (pull ?p [*])
         :in $ ?input ?input2
         :where
         [?t :block/name ?input]
         [?p :block/tags ?t]
         [?t2 :block/name ?input2]
         [?p :block/tags ?t2]]}
#+END_QUERY

Thank you, that works perfectly!

1 Like

Is the status also a page-property? As in, in the same block as the tags:: programming with status:: ongoing?
If so then add this:

[?p :block/properties ?prop]
[(get ?prop :status) ?status]
[(= ?status "ongoing")]

Alternatively if you want to add it through the inputs, add an extra input as per the double tags example and use that input instead of "ongoing" (as in: [(= ?status ?input2)] )