Tasks plugin - How to use higher order headings in query?


I use the following query in my project notes, to list all open tasks of that project:

(heading regex matches /202[234]-[01][0-9]-[0123][0-9]/) OR (heading includes ToDos)
folder includes Project-folder
not done

With that query I can look for tasks, that are located directly under a heading, which includes “ToDos” or any date.

But if I use further sub-headings, the tasks are not found…

=> Do you have an idea, how to use higher order headings in tasks-queries?

I’m sorry to say that I believe both Tasks and the task queries of Dataview only respect/handle the heading immediately before the task itself.

If you’re dead set on accomplishing this goal, you would need to parse the headings section of the metadata for a given file, and correlate the task position with a self maintained heading hierarchy.

Given a headings section like the following:


You could scan through, and see that H2 one on line 1, is followed by H3 one_one on a line inbetween, but “replaced” by H3 one_two on line 9, so that if you had a task at line 10 (which is still before H2 two on line 12), then that task would have the headers “H3 one_two” and “H2 one”, and you could do your check to see if “H2 one” matched the date regex or not…

See the following threads and links for a little more on the headings metadata:

Hope this gives you some insight into how to tackle your issue at hand.

Another approach to how to do the actual filtering in your case could be something like the similar:

  • Scan through each of the headings, and see if any matches your regex. If they do, take note of the heading level, and the line it’s at
  • Keep scanning headings and see if you find a heading at the same level. If you do, take note of the line number (also note the line number if you reach the end of file). The line number from previous item, and this line number is now the “valid” range for your tasks in this file
  • Depending on your file structure, you could repeat the previous steps to find multiple ranges matching your regex
  • Afterwards, scan the tasks and only list tasks where their line numbers is within the found range

Does that make sense to you?

1 Like

Thanks holroy for your detailed answer!!! :slight_smile:
… but I think, these solutions are a bit too complicated for me, so I’ll have to stick to the query above and limit myself to only write tasks in headings with a date or a “ToDo” in it… - that’s also feasable :slight_smile:

Most people would benefit from adapting their text/setup and making it easier for themself that way, so good call @SiliasOS .

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.