I grabbed code from org effectiveness as shown below:
(defun org-effectiveness-count-todo() ;;org-effectiveness-count-todo "Print a message with the number of todo tasks in the current buffer" (interactive) (save-excursion (goto-char (point-min)) (message "Number of TODO: %d" (count-matches "TODO"))))
When I put org-effectiveness-count-todo in any buffer, it shows TODO count correctly. When I put this code in agenda header, it shows only zero.
(org-agenda-overriding-header (org-effectiveness-count-todo) ...