[Solved] Advanced querie to get blocks referencing a page with a specific tag

Hi, lets say I have some pages in my graph with the tag “book”, and I want to get all the blocks in these formats:

TODO [[Alice in Wonderland]]

Alice In Wonderland is a page with:

tags:: book, some other thing

Or also return block if its like:

TODO Alice in Wonderland #book

So, as a part of my querie I have the following rule, wich can return

[(refers-to ?b ?tags)
[?b :block/refs ?ref]
[?ref :block/name ?ref_names]
(or
[(contains? ?tags ?ref_names)]
(page-tags ?ref ?tags)
)
]

page-tags is the rule from https://github.com/logseq/logseq/blob/master/deps/db/src/logseq/db/rules.cljc, I don’t know why but I had to copy it to my :rules statement to avoid error.
This does return this format:

TODO Alice in Wonderland #book

But no:

TODO [[Alice in Wonderland]]

Any help would be welcome!

EDIT: SOLVED
I figured out that I was bad understanding how page-tags work, instead I used:

(page-property ?ref :tags ?tags)

If you provide actual queries, more people would bother reproducing your issue and try to help.

Hello, do you have the full code of the query that worked for you? I am looking to do the same thing.

Funny story, I ended up figuring out a version of this that worked for me but actually stopped working as of today when I checked it.

Previously it would result in a table of journal blocks which was the desired result.

Today is gives this error:

Cannot compare :block/parent to :block/journal
#+BEGIN_QUERY
{
	:title "Journal blocks between two dates with reference to a page with tag 'book'"
	:query [
      :find (pull ?b [*])
		:in $ ?start ?today
		:where
            [?b block/journal? ]
            [?b :block/refs ?refs]
            [?refs :block/tags ?t]
            [?t :block/name "book"]
            (between ?b ?start ?today)
	]
 	:inputs [20231201 :today]
}

#+END_QUERY

Your block/journal? is missing the colon : at its beginning.

1 Like