Group tasks by heading OR tag

Tasks question for the group: Is it possible to filter tasks by a tag OR a heading?

What I’m trying to do

In my daily note I have a section called “Tasks Inbox”. That is where I enter all random tasks as they come to my mind. If I know where a task needs to go, I’ll give it a tag at that time. If I leave it without a tag, I have a tasks query setup as an “Inbox” where it shows all tasks without tags so I can put them where they need to go when I have time.

I also take meeting notes with my daily note and use a tag as a heading for these notes. Currently, if I input a task during a meeting, I have to add a tag to the task for it to be properly categorized. Since my meeting heading uses the same tags schema as my tasks, I would like to be able to just enter tasks during a meeting without having to add a tag to each individual task.

In summary, if I’m entering a task using the “Task Inbox” I can give it a tag at that time, say #project. If I am taking meetings notes for #project (using #project as a heading), I would like to enter tasks under that heading without having to add a tag to each task. I would then like to be able to see all tasks with either the individual tag #project OR that are in a list with the heading #project in the same place.

Things I have tried

I current have a master Tasks document setup where I use this query to display all tasks by their tag:

tasks
has tags
group by tags
not done

I’ve tried tweaking this code a few different ways to grab either the tag OR the heading but I can’t get it to put them all together in one group.

Thanks in advance!

Ok, so I think I solved this issue if this helps anyone. In order to group tasks by tag OR heading I used the following query:

tasks
not done
group by function if (task.tags != ``) {const newheading = task.tags; return newheading;} else {const newheading = task.heading; return newheading;}

Essentially, this checks to see if a task contains a tag. If it does, write the task.tags value to a new variable called newheading and then return that to the query. If a task does not contain a tag, then write the task.heading value to our newheading variable and then return that to the query. I know next to nothing about javascript so this was very much hacked together from a bunch of googling so I’m sure there is a much more elegant way to accomplish this, but for now it is working for me. I now see tasks in the same group if they have the #project tag OR the #project heading (or whatever tag/heading combo I use).

Not tested, as I’m not using Tasks plugin, but couldn’t this also be written as:

tasks
not done
group by function if (task.tags != ``) { return task.tags } else { return task.heading }

Not tested, just an idea based on general experience with programming.

Yep, that worked as well (and is simpler than what I came up with for sure). Thanks for sharing.

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