Posted May 25th, 2007 @ 08:57am by Erik J. Barzeski
Though I don't assign multiple categories to posts here at nslog.com, I do at The Sand Trap in two instances: for "Hot Topics" and "Reviews." The former helps me fill out the "Top Stories" section in the sidebar and the latter simply helps me direct people to our reviews (via
I discovered in WordPress 2.0.x and 2.1.x that categories were sorted by their category ID (cat_ID) in an ascending order. On posts with multiple categories assigned, cat_ID 4 took precedent over cat_ID 5 or 6 or 99. This precedence exhibited itself in two places: building of permalinks (URLs) and the category list (via WordPress's
I don't care about the latter much, but the former is important to me. I don't want "Reviews" or "Hot Topics" to be used to build URLs, so I set their cat_IDs to 98 and 99 respectively (with a parent category, "Tags," set to 100). All other cat_IDs are lower, and life was good. URLs were "properly" built based on the behavior I saw in WordPress 2.0.x and the behavior continued when I upgraded to WordPress 2.1.x.
With WordPress 2.2, this behavior has flipped around. No longer are categories listed in ascending order, but rather in descending order. This change in the way WordPress behaves effectively changed every URL on my site which has multiple categories. This goofs up things like Pingbacks, not to mention the fact that URLs are no longer the way I want them. The old Permalinks still work fine, but the "new" (and incorrect) permalinks are pushed out by the system wherever it has control over link generation.
This error, bug, or "accidental change in behavior" exposes a nasty flaw in WordPress - the inability to set a "primary" category. MovableType had this feature, and it worked as it should. WordPress lacks this feature, and now the behavior I relied upon has been changed for seemingly no reason.
Put another way: permalinks (URLs) used to be built from the category with the lowest ID. Now they're built from the category with the highest ID. Category lists used to be in "low to high" order, and now that order too appears reversed.
Some specific examples:
I'm not sure where this changed in the WordPress code base (or, again, why), but I do know this is not the result of some plugin or any modifications I've made.
I suspect I could likely "solve" the problem by manually editing my database (both
wp_post2cat) to move categories with IDs 1 to 33 to be higher than 100, but that's a lot of work for what is probably a simple "ORDER BY _____ DESC" somewhere.
If anyone can shed any light on this subject, I'd appreciate it. Trac ticket is here.