Q:

Capture todos to the last Tasks heading

I have such a diary structure 
*** 2019-07-28 Monday 
**** Tasks
*** 2019-07-29 Tuesday
**** Tasks

Desire to capture todos under the Tasks of latest day
(setq org-capture-templates '(("t" "Todo [inbox]" entry (file+headline "~/ORG/src/sdiary.org"
                                                                       "Tasks") "* TODO %i%?")
                              ("T" "Tickler" entry (file+headline "~/ORG/src/tickler.org" "Tickler")
                               "* %i%? \n %U")))

conversely, it collect todos to the first Tasks not the tasks at the bottom of the file.
How could capture todos to the last tasks rather than the first tasks.

A:

You can use filename+function as described in the manual:

‘(file+function "filename" function-finding-location)’
A function to find the right location in the file.

The following function moves the point to the last headline matching **** Tasks:
(defun my-org-goto-last-tasks-headline ()
  "Move point to the last headline in file matching \"**** Tasks\"."
  (goto-char (point-max))
  (re-search-backward "^\\*\\*\\*\\* Tasks"))

Then use this function in your capture template as follows:
(setq org-capture-templates
      '(("t" "Todo [inbox]" entry
         (file+function "~/ORG/src/sdiary.org"
                        my-org-goto-last-tasks-headline) "* TODO %i%?")
        ("T" "Tickler" entry
         (file+headline "~/ORG/src/tickler.org" "Tickler") "* %i%? \n %U")))

