I would like to make and insert a link [[id:retrieved-id][retrieved-title]].

retrieved-id is returned by selecting the subtree I want from a list of titles. The list, selection and returned ID is accomplished by (org-id-get-with-outline-path-completion org-refile-targets).

org-id-get-with-outline-path-completion returns the ID but not the text of my selection. How do I retrieve the title/headline text associated with retrieved-id?

  • This seems a bit circular to me: you want to find the text of the headline that has a certain ID, but you get the ID by basically specifying the headline - am I missing something?
    – NickD
    Commented Sep 16, 2022 at 2:59
  • 1
    I edited the OP to clarify. I am specify the headline by choosing from a list. What I select is not returned by org-id-get-with-outline-path-completion. It only returns the ID, as far as I can tell.
    – midas0441
    Commented Sep 16, 2022 at 17:13
  • Thanks for the clarifications!
    – NickD
    Commented Sep 16, 2022 at 17:44

1 Answer 1


There are many ways to approach this, but starting from org-id-get-with-outline-path-completion the first thing I can come up with is using

(defun insert-id-link ()
  (let ((id (org-id-get-with-outline-path-completion)))
      (goto-char (org-find-entry-with-id id)))
    (insert (org-link-make-string (concat "id:" id)

(I am not sure if you really need to add the org-refile-targets, but if so, then simply add it).

  • If I understand the gist of it, the function has to 'visit' the subtree using org-find-entry-with-id to get its headline/title using org-entry-get. The save-excursion does the visiting in the background, i.e., I won't see buffer changes as the function executes. Is that an accurate understanding of your function?
    – midas0441
    Commented Sep 16, 2022 at 17:16
  • Is there a way to get the title by looking up the hash table of org-IDs and their locations? Isn't that how org-find-entry-with-id finds where to go?
    – midas0441
    Commented Sep 16, 2022 at 17:20
  • No, org-find-entry-with-id searches the current buffer for ID properties.
    – NickD
    Commented Sep 16, 2022 at 18:10
  • The hash table contains entries with the ID as index and the filename as value. So the file has to be visited in order to find the headline with the required ID.
    – NickD
    Commented Sep 16, 2022 at 18:19
  • @dalanicolai: does this work for anything other than the current file? I would expect to see org-id-find called.
    – NickD
    Commented Sep 16, 2022 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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