WordPress Category Tree Chaos at “Write Posts”
codestyling | 07. December 2008 | 19:17
While writing new posts you will realize, that something is wrong with the tree view of all categories. WordPress lists all categories as tree and i expect that the defined tree structure will be shown all the time.
Unfortunately WordPress steps in with an unexpected manner which forces the tree view to be shown damaged. The sorting of already used categories for the actual post in front of tree breaks the tree view and makes a tree view obsolete.
Again i was searching the code lines at WordPress Core, that are responsible for this damaged display. Finally i found it at the file template.php inside the function wp_category_checklist. The function tries a pre-filter on categories, which already have been used for this post. This results into creation of 2 disjuct sets of categories:
- categories already assigned to this post
- all unassigned remaining categories
Afterwards both sets will be dumped as HTML tree views. Because of this rupture of tree connections only a part of the categories can be shown as tree view. All not found parent relations will result into appending the categories in linear order at the end of possible tree. The above shown image may illustrate this issue in a simple way.
The only solution i found is a modification of WordPress Core. That’s why i changed the file: wp-admin/includes/template.php at function wp_category_checklist and have commented out the pre-filtering:

The red marked section is the pre-filter not longer been executed but keeped for the moment at file. But i was also curious to know, what other WordPress versions have a similar coding to this. After inspectation of all versions beginning 2.7-RC1 downto 2.5.1 i realized, that this code can be found unchanged at all of them. So the patch can be applied to all this versions as shown here.
As you can see the result is a logical tree view, that displays correctly the relationship of all categories as expected. This patch is a simple solution to solve this issue. In my opinion the WordPress core team has to find a more sophisticated solution. If categories will be shown as tree than all relations should be displayed in a way that meets the parent relationship defined at category page.
I will register this issue at WordPress Bug Trac and will try to explain it there. Hopefully an appropriated solution will be published at upcomming releases of WordPress, but i’m afraid, that it is too late for next version 2.7 published soon.
The issue has been filed at WordPress Trac as follows: Ticket #8521






ricky
22.01.2009 | 08:10Thanks for this post you really save me some time.
reply »
jimc
25.03.2009 | 17:32Great find. Huge problem in WP.
reply »
josh
30.04.2009 | 17:40You are the man! Thanks so freaking much. This was a real oversight on WP’s part, and there is very little addressing this on the net.
Thanks again!
p.s. Some of the google keywords I used for this issue were as follows:
wp category hierarchy edit admin post breaks broken selected tree
Figured I’d stick them here just to make sure your page comes up more easily for this issue.
reply »
David McDonald
05.10.2009 | 08:07Wondering if there is a way to do this without having to modify a core file?
reply »
Eivind
03.12.2009 | 15:15Thanks for this heads-up. Took me some time to find it. Looking at my 2.8.5 files, it seems that the code has been changed, but that the bug persists. Your fix cured the problem.
I looked at the ticket and it shows a link to a duplicate issue. Following that to its end, it says it’s closed because there is a better idea out there. But that idea was suggest YEARS ago, and has still not been implemented, so I think this is now a forgotten issue.
Please reopen a ticket (I’m not going to try because I’m not really a developer)
Anyway, thanks for the info
E
reply »
Kadrwa
13.09.2010 | 14:20I have an extensive list of categories so at admin, i want all parent categories to be collapsed and want any specif category to be expanded when someone click or double click on a parent category. Any suggestion on how can I acheive this?
reply »
codestyling
14.09.2010 | 00:42This is a big problem because this would require first a core file modification and second a high sophisticated javascript file. All versions of WordPress change slightly the script versions and also the markup, so this 2 points make it extremly difficult.
As long as the WP core won’t support it, I’m afraid, there won’t be a reliable solution for.
reply »