Query Todos on Current Page

Hello! I’m struggling to figure out how to write a query to get all the todos on a particular page. I thought there might be a generic way to do this for any page, but I’m even struggling to get it to work for a specific page using the page’s name. I think part of it is that I’m just learning the query syntax. Here’s what I’ve tried and learned:

  1. {{query todo}} gives all the todos in my entire database
  2. Then I tried to use a filter by page: {{query todo [[the book]] }} (“the book” is an alias to the page I’m trying to collect todos from). This is giving the same results as #1, which surprised me.
  3. I thought, maybe I need to explicitly use logical expressions to tie the parts of the query together. So I tried {{query (and todo [[the book]]) }}, which was empty.

I’d appreciate any help filling the gaps in my knowledge and creating a query that collects todos on a given page.


Query works for me when To-Do states explicitly specified {{ query (and (todo todo doing) [[the book]]) }}.

Thank you @c6p, that worked! Now, any ideas on making this a more general query that will work on any page? I see that for templates there is a “current page” variable, but that doesn’t seem to apply to queries. I’ve also noticed some references to current page in the advanced query syntax, so maybe that’s where I need to be looking…

Check out https://logseq.github.io/#/page/dynamic%20variables

{{query (and (todo todo doing) (page <% current page %>))}} grabs To-dos for current page.


Thanks, I missed the “syntax” line on that documentation page when I was looking at it. I appreciate you taking the time to reply and share!

See my feature request for a “page specific NOW section”.

1 Like

Shouldn’t this later reply by c6p be marked the solution @jafish?

Yes, thanks! I didn’t realize you could only mark one solution. I had marked them both, in reverse order, and, well, you saw what happened :wink:

1 Like