alphapapa / org-ql

A searching tool for Org-mode, including custom query languages, commands, saved searches and agenda-like views, etc.
GNU General Public License v3.0
1.35k stars 104 forks source link

How to use variables correctly in query statements? #353

Closed iT-Boyer closed 1 year ago

iT-Boyer commented 1 year ago

I need to query related items by statement and then get the content.

(setq test (org-ql-query
               :select '(org-get-entry)
               :from buffers-files
               :where '(and
                        (ancestors (heading "hello world"))
                        (heading "system")
                        )
        ))

Now I want to set the heading value dynamically, but I cannot query the result when the heading is set as a variable.

(setq itemTitle "hello world")
(setq test (org-ql-query
               :select '(org-get-entry)
               :from buffers-files
               :where '(and
                        (ancestors (heading itemTitle))
                        (heading "system")
                        )
        ))
iT-Boyer commented 1 year ago

fix by https://github.com/alphapapa/org-ql/issues/241#issuecomment-895334584

(setq itemTitle "hello world")
(setq test (org-ql-query
               :select '(org-get-entry)
               :from buffers-files
               :where `(and
                        (ancestors (heading, itemTitle))
                        (heading "system")
                        )
        ))