Queries and reuse of variable name

I’m new to Logseq (after using TiddlyWiki, Roam and Obsidian) and I’m truly impressed by its abilities. Usage is quite straightforward, except for advanced queries. I have the following query where I want to list all blocks containing both the tag “note” and the tag representing the current page (the current page being the page representing the person I talked to)

{:title "All blocks with tag project"
 :query [:find (pull ?b [*])
         :in $ ?current-page
         [?p :block/name "note"]
         [?z :block/name ?current-page]
         [?b :block/refs ?p]
         [?b :block/refs ?z]]
 :inputs [:current-page]

This works fine on the first page I put the query on. On the second page, the query runs but uses the value of ?current-page from the first page. How does one deal with this kind of problem?

Leaving a note here for the same issue, and I cannot for the life of me figure out what/why. Any solutions?

Just found this bug report: Advanced query with `:current-page` on macOS/iOS desktop app return wrong results when switching different pages · Issue #4156 · logseq/logseq · GitHub Open since Feb :cry: although it was given Pri A a few weeks ago… :crossed_fingers:

Ah, thanks for this info. So we just have to wait till the bug is fixed …

Just found a way of doing this in a simple query!

{{query (and (task todo doing) <% current page %>) }}

Gives you all the todo tasks that are also tagged with the name of the current page - I’m using it to gather all todo’s for Bob on [[Person/Bob]]

I think {{query (and [[note]] <% current page %>) }} would work for your case?

Yes, this works, thanks. Still, being able to use the advanced queries’ additional features like controlling the display of the output would be nice

1 Like