The category of items in an "agenda" block view as returned by org-agenda-get-category are truncated based on the value of the prefix format; this isn't the case for e.g. the tags-todo view. For instance, if an item has a category "marathon training", and your agenda and tags-todo views both have prefix formats of " %8.8:c ", calling org-agenda-get-category on that item while it's being displayed in the agenda will yield a category of "marathon", while calling it on the same item in the tags-todo view will yield "marathon training".
This poses a problem while trying to use custom commands to do a block agenda, since if you call org-agenda-filter-by-category on an entry with a given category, other entries with that same category can get filtered out if they're in a different view than the point was in when you filtered. To recreate this issue, I: 1. Started emacs with emacs -Q 2. Ran eval-defun on the following elisp (setq org-agenda-custom-commands '(("d" "demo" ((agenda "" ((org-agenda-prefix-format " %-12.12:c "))) (tags-todo "/TODO" ((org-agenda-prefix-format " %16.16:c "))) (tags-todo "/TODO" ((org-agenda-prefix-format " %-12.12:c "))))))) 3. Created an org file with the following contents and added it to org-agenda-files with C-c [ * TODO This is a small project :PROPERTIES: :CATEGORY: small proj :END: ** TODO Do foo SCHEDULED: <2024-02-22 Thu> * TODO This is a big, special project! :PROPERTIES: :CATEGORY: extra-special project :END: ** TODO Do bar SCHEDULED: <2024-02-22 Thu> ** TODO Do baz 4. Opened org-agenda with the "demo" view. Now, if you use org-agenda-filter-by-category while in the agenda block on the scheduled entry "Do foo", you'll see the category filter appropriately in the tags-todo view, only leaving items with category "small proj". However, if you use org-agenda-filter-by-category on the scheduled entry "Do bar" in the agenda block, all items are filtered out in the tags-todo views, including ones that should have the same category. Calling org-agenda-get-category on the "Do bar" item in the agenda yields "extra-speci" as the category of that entry. Note that if you instead filter on "Do bar" while on one of its entries in the tags-todo views, the entries in the other tags-todo view are filtered correctly, despite them having a different length in their prefix format; calling org-agenda-get-category on either of those both yield the full "extra-special project" category. My workflow involves giving significant projects a category, and organizing tasks underneath those headings; then, I can schedule individual tasks so that they show up on my agenda, and filter the agenda tasks by category so that I see all other tasks that belong to that project in a larger tags-todo view underneath the agenda. However, this will now only work if I don't truncate the headings at all in my agenda prefix-format so that they match the untruncated categories of the tags-todo view, which is unfortunate, since it throws others stuff in the agenda out of alignment. (Due to projects sometimes having sub-projects, org-agenda-filter-by-top-headline isn't a cure-all here). In general, it seems like org-agenda-filter-by-category should work based on the actual category of an item, rather than its display in the buffer, which I find unexpected. I wasn't able to find any configuration to change this behavior, but if I'm missing it, I'd appreciate a point in the right direction! This was recreated on GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.41, cairo version 1.18.0) of 2024-02-14, with Org mode version 9.6.15 (release_9.6.15 @ /usr/share/emacs/30.0.50/lisp/org/) Best, John