It's basically "What links here?".

Using Org mode links, I'd like to be able to get the list of headings which contain a link to a specific heading.

Example file:

* Target
  :ID: 509039F8-5B43-4C9B-8FA3-F37E3A2EEC10

* Heading containing link


* Another heading containing the same link


When the cursor is at Target, I'd like to get the list of all headings that link to it:

* Heading containing link
* Another heading containing the same link
  • This should be enough to get you started: (let ((id (org-entry-get (point) "ID")) result) (save-excursion (goto-char (point-min)) (while (re-search-forward (concat "id:" id) nil t) (push (org-get-heading) result)) result)) You can look at org-id-update-id-locations to see how to get a listing of all files that may contain ID and you can loop through each file. You can create a variation of org-get-heading if you need something a little different -- e.g., gather the stars, or use match-string-no-properties if the text properties are not to your liking.
    – lawlist
    Feb 20, 2017 at 23:26

2 Answers 2


A different approach in a single file is below. It avoids the direct use of regular expressions.

(defun get-headings-with-links ()
  (let ((tid (org-id-get)))
    (org-element-map (org-element-parse-buffer) 'link
      (lambda (link)
    (when (and (string= (org-element-property :type link) "id")
           (string= (org-element-property :path link) tid))
        (goto-char (org-element-property :begin link))

I ended up simply using:

(defun what-links-here ()
  (let ((id (org-entry-get nil "ID")))
    (if (> (length id) 0)
        (org-search-view nil (concat "id:" id))
      (message "No ID - nothing can be linking here"))))
  • Result is exactly what I needed, but perhaps there's room for improvement.
    – ooi
    Feb 22, 2017 at 5:38

Your Answer

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

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