Query that excludes tasks from pages with a specific page property

Hi there,

I am new to logseq and already learned many things by reading comments in this forum. But for the following question I couldn’t find an answer, unfortunatly. I have organized my projects and all of them have tasks in their page. For tasks relevant to the project, that are not directly on the project page but are linked to it I have a query. What is missing is a list of tasks, that are not part of these projects. For that I tried to find a custom query, that pulls all tasks from my database but excludes tasks that are on project pages (page property: project page) or link to them. Is this possible?

Many thanks in advance,

Welcome. Yes, it is possible. If you provide your query, we will suggest the clauses that perform the exclusion.

Thank you for your answer. As I am new to this, I try to adapt and understand queries that I find online. Unfortunatly, I couldn’t find any for this case. Could you point me in the right direction?

Could you share the query that you have?

Sure, but that query works just fine and is meant to be separate from the other one. This query is directly on each project page, but the query I am looking for shall be on another page that will probably contain a list of my projects and a query that lists all tasks not related to a project or on a project page.

{:title [:h3 "Related Tasks"]
:query [:find (pull ?b [*])
     :in $ ?query-page
     [?p :block/name ?query-page]
     [?b :block/marker ?marker]
     [?b :block/refs ?p]
     [?ref :block/name "project"]
     (not [?b :block/refs ?ref])
     [(contains? #{"TODO" "DOING" "NOW" "LATER" "WAITING"} ?marker)]]
:inputs [:query-page]
:result-transform (fn [result]
                 (sort-by (fn [b]
                            (get b :block/priority "Z")) result))
:breadcrumb-show? false
:group-by-page? false
:collapsed? false

I’m not fully following your description (not everything below makes perfect sense), so this is going to be a step-by-step effort:

  • We are focusing on the :where portion of the query:
    1. The following part is for tasks:
             [?b :block/marker ?marker]
             [(contains? #{"TODO" "DOING" "NOW" "LATER" "WAITING"} ?marker)]]
      • Normally this part should also exist in the new query.
    2. I suppose that the following part is for excluding blocks that are “directly on the project page”:
           [?ref :block/name "project"]
           (not [?b :block/refs ?ref])
      • This part should also exist in the new query, but it looks suspicious for more than one reasons:
        • Checking for the page of a block, is usually done with :block/page
        • Given that [?b :block/refs ?p] is already used above, should be either:
          • (not [?p :block/name "project"])
          • (not [?ref :block/name "project"]
                 [?b :block/refs ?ref])
    3. I suppose that the following part is for blocks that are “related” to the project:
           [?p :block/name ?query-page]
           [?b :block/refs ?p]
      • This needs to be negated:
             (not [?p :block/name ?query-page]
                  [?b :block/refs ?p])
      • But given that the new query will be used in a different page, should replace ?query-page with:
        • to exclude a specific page: the name of that page
        • to exclude all project pages: a group of conditions that:
          • all of them are inside the same not
          • in combination select the project pages
            • Create and test this (sub-)query separately, then include it here.
            • It probably has to do with page property: project page, which I don’t fully understand.
  • This is why I insisted for the existing query. If the above gets cleared-up, we get very close to construct the new one.

Thank you for your efforts and sorry for the late reply. I did not understand everything in your reply, but it seems that my explanation was unclear. In the meantime I have found another solution which I will share below. First I will again try to explain what my goal is. I have three kinds of tasks: 1. tasks that are directly on a project page but are not tagged. I want to organize these tasks manually. 2. tasks, that are not on a project page, but are linked to it. The query you tried to explain was meant for these tasks and works fine as I posted above. 3. tasks that are not related to a project in any way and are normally on a journal page. I was looking for a query that collects these tasks, but failed to explain this properly.

The solution I found for tasks of the third kind is the “Unfinished Business” plugin, which allows tasks to be automatically moved from yesterday’s journal to today’s journal.

Thanks again for your help and have a nice day,