0

I have an org file tracking my tasks across various projects:

work.org

* Job 1
** Tasks
*** TODO rewrite frontend in coldfusion
* Job 2
** Tasks
*** TODO Convince boss to buy stadium

I can do an org-capture-template to capture tasks to work.org's Job 1 header or Job 2 header, but what about Job 1 > Tasks, and same for Job 2?

For example:

  (setq org-capture-templates
          ("j" "Job 1" entry (file+headline ,(concat org-directory "/work.org") "Job 1")
           "* TODO %? \n"))

I tried, in place of "Job 1," "Job 1 Tasks," but that created a new top-level headline called "Job 1 Tasks." Based on a somewhat unrelated stackoverflow answer, I tried "*Job 1 Tasks", but again, that just created a new top-level headline.

How can I refer to a sub-header in an org-capture-template?

2
  • I haven't checked but I don't think you can do that: it will search for a headline, so the matcher must say e.g. "Tasks", but it's not possible to disambiguate the first Tasks from the second. But I may be wrong.
    – NickD
    Mar 30, 2022 at 3:51
  • I was wrong: file+olp, as @TianshuWang points out in his answer, does the trick.
    – NickD
    Mar 31, 2022 at 14:31

1 Answer 1

3

You can use file+olp like:

(setq org-capture-templates
      ("j" "Job 1" entry (file+olp ,(concat org-directory "/work.org") "Job 1" "Works")
       "* TODO %? \n"))

For more details, please refer to the doc of org-capture-templates through C-h v org-capture-templates.

3
  • I forgot about file+olp ...
    – NickD
    Mar 31, 2022 at 14:29
  • How would you make the level 2 heading a variable to be prompted, as opposed to preset (in this case to "Work")? emacs.stackexchange.com/questions/75422/…
    – Erwann
    Jan 17 at 18:00
  • I thought it might be necessary to use file+function and write you own function to prompt and find the right location. Jan 18 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.