How to Query the Parent of a Task?

Hi everyone

I’m trying to figure out how to query the parent of a task.

Tasks appear to have a parent attribute that points to a specific position in a page (if it’s not undefined). Is there a way to retrieve the text of the parent node for a task?

Use Case: I want to query all tasks that either:

  • Mention the current page, or
  • Have a parent node that mentions the current page.

Does anyone have suggestions or examples of how to accomplish this?

Thanks in advance for your help!

2 Likes

I know I’m months late to the party, but from my experimentation it looks like the parent attribute doesn’t actually line up perfectly with the parent’s ref. The parent’s ref attribute can be turned into the child’s parent attribute with: page + "@" + (pos - 2)

This is my shopping list template that queries all the parent tasks specifically and then queries their children (which is a lot faster than doing it the other way around)

{{#each {task where page = @page.name and parent = null and done} }}
{{#let @parent = page + "@" + (pos - 2)}}
{{ {task where page = @page.name and parent = @parent and not done render [[Library/Core/Query/Task]] } }}
{{/let}}
{{/each}}

But doing it this way can be very inefficient because it ends up running a lot of queries (especially if you want to check every task’s parent)