WordPress get_nested_categories() Bug [en]

Some code I produced while trying to fix and already fixed Wordpress bug (in get_nested_categories()).

I bumped into my first really annoying WordPress bug today. The function get_nested_categories(), which is used to display the different categories available in the admin screens, wrongly assumes in 1.2 that people create their parent categories before their children (and that the latter have a higher ID than the former).

This has been fixed in the CVS. However, as there have been changes since 1.2 in CVS, you need to copy the code provided on the bug report page. Take the first function from the “Additional Information” part, and the second one from the “Bug Notes” section.

As I didn’t know about the web-based CVS, I started trying to fix the bug myself. It’s almost finished but doesn’t work yet (just a little bug to track down), and it only uses one MySQL query, whereas the fix presented above can end up using lots, if you have a complicated hierarchical category structure like mine. You’re welcome to have a go at my code — let me know if you find the problem!

Next time I meet a bug, I’ll check in CVS first to make sure it isn’t already half dead.

Batch Category Editing For WordPress [en]

I put together an admin screen for WordPress today which allows changing multiple categories of multiple posts at the same time. Code available, no guarantees.

[fr] J'ai codé une extension à  WordPress qui permet d'éditer les catégories de nombreux billets en un coup. L'écran liste par exemple tous les billets d'une catégorie, accompagnés d'un certain nombre de selects. On effectue les modifications que l'on désire et on soumet le formulaire entier en une fois.

Update 13.07: A more recent version is out!

I had planned to give you a write-up of the beginning of my WordPress experience today. Unfortunately, I decided to clean up my categories somewhat before I did that, and I managed to badly mess things up.

The result is that I spent most of my day writing a Batch Categories admin screen to help me clean things up. It was something I had planned to do, and I suppose it will also be useful to other people.

If you want to play around: copy the code above into a file named batch-categories.php in your wp-admin directory. I highly recommend that you back up your wp_post2cat table before you get going. This script works for me, but hasn’t been tested much, and comes with no guarantees. It is not optimised either, so depending on how many posts and categories you list, the screen can very well take over half a minute to load!

There are still a few functionalities I want to add, in particular: assigning all listed posts to a category in one go (or removing them).

If you want pretty integration with the other screens of the Edit menu, you’ll have to tweak the navigation bar in edit.php, edit-comments.php, and moderation.php.

Update 24.06.04: I’ve uploaded a screenshot of the admin screen so you can see what it could look like.

Update II 24.06.04: Instead of hacking the Edit menu bars, you can also access the Batch Categories screen from the Plugins page: create a file called batch-access.php (e.g.) in your plugins directory. (Beware not to leave any whitespace after the ?>, though, or you’ll get errors. Promised, zips and more detailed documentation will follow.

Update 04.07.04: I tried using the script this morning, and it seems nastily broken (removed all categories for some posts). Use with caution, and get back to me if ever you hack it or modify it, I’m interested! I’ll look into this once I get back home from Vienna.

Update 12.07.04: The script now works as it should! Thanks to Ben and MooKitty for helping me nail the big nasty bug which was driving me bonkers! Two improvements I’m working on right now: making the code more efficient by using the category cache, and adding a “add all listed posts to category X” option.

CSS Lists [en]

I’m having CSS problems, for a change. List margins that show up too small in Netscape. Let me know if you have explanations or a solution…

J’ai des problèmes de CSS. Alors au cas où vous voudriez jeter un oeil, la table est mise !