25

A Bug I Found With WordPress 3.0 Taxonomies And wp_nav_menu

Whether this is a bug, or just an incomplete feature missing some sort fallback code, I believe it to be a mid to higher priority for fixing. I have had to reset WordPress twice after I was unable to find a fix for the broken menu system....
A Bug I Found With WordPress 3.0 Taxonomies And wp_nav_menu

Learning The Hard Way

While I was working on developing a theme today I stumbled onto a really annoying thing that involves taxonomies and the new WordPress nav menu system. It's likely it would also happen with custom post types too but that I have not tested to know for sure or not. I have submitted a ticket #14181 for it, but it apparently was already reported here #13958.

So here's the deal...

Digging Into WordPress

I set up a custom taxonomy to add to the 'posts' post type. I then post a new sample post, which I created the hierarchy of terms for the custom tax I made, all of which I checked off to apply them to my sample post. That way there would be none that had an empty value.

I then created a new wp_nav_menu(), which I was planning to used as a drop menu for only displaying the terms of the custom tax I made. I set the menu up with the parent terms and each child term beneath them. The menu worked great, dropped down nicely, and was just fine and exactly what I was trying to do.

But then...

Naturally once I got it all working and doing what I wanted, I have to go and break that which is perfectly fine and completed. I decided that I needed to change the taxonomy's name, slug, query_var, etc. Basically I re-created the custom taxonomy using a different word for what it was called.

First let me explain why I not only did this, but I did it two times, and each time learned why it was a bad idea for me to do. The reason for changing the name of it the first time was because the original taxonomy I made was really just a generic thing, quickly done just to get it set up. The second time I re-named it was because I then needed to create a second custom taxonomy so I could use the two taxonomies as sort of the top level 'parent term' of the child terms. Only they were not terms, but more like separate containers that just needed to hold the child terms.

Update! - I jut awesomely did it for a 3rd time. I now know that it can happen even more likely to those less-savvy WordPress users. If you have a custom taxonomy and include terms of it in a nav menu, then you then decide to change your site theme to use a different one sort like how I just did, without removing the terms of the custom taxonomy first before changing themes. Yeah well, you're screwed then..

Taxonomy->Terms->Menu->Taxonomy Remake

This is a big No No...

Basically what I did was create something, add a whole bunch of things which use that something. Then took that whole bunch of things and added them to another thing which, is then dependent on that something as well. Then I destroyed that something and made a new thing, leaving those other things that were dependent on my somethings existence up the creek without a paddle. They were killed on impact.

WP Rockstar
In other words, when you add a bunch of terms for a custom taxonomy to a menu using the wp_nav, and then go and change, or re-create, re-structure, the taxonomy which the terms in the menu use. What is the result???

BOOM!!!

When I did this the first time I spent hours completely baffled as to what the hell could've happened, and searched and searched for some sort of answer. I read though some WordPress source files, and all kinds of possible explanations, only there was nothing helpful were to be found that involved my problem.

The Php error I was getting on my (now horribly broken page that was working perfectly before) was this:

Catchable fatal error: Object of class WP_Error could not be converted to string in C:\wamp\www\wp-includes\formatting.php on line 2829

On a side note: If you go and view line 2829 in this file, like I did, You will notice that the line the error occurred on is extremely unhelpful for figuring out what's broken, but it is humorous what the function this line falls on though.

So Yeah, This Bug Bites

Not only did I get the error above on my pages where the wp_nav_menu() function was called, in my dashboard on the menu management page this error was displayed, on a very broken and almost blank white page:

Catchable fatal error: Object of class WP_Error could not be converted to string in C:\wamp\www\new2wp\wp-includes\formatting.php on line 433

I am still not entirely sure about whether or not this is a bug, or some other type of thing I don't know about. After all, it was something that I only experience two times, and as far as I could find, those are the only two times it's happened. WordPress 3.0 is still extremely new, so I would imagine since I did it twice in one day, there are likely to be more people that it will happen to in the future if something isn't done to fix it.
Page.ly - WordPress Hosting
I don't really even know what the hell is the problem, but it obviously has to do with taxonomies and the use of terms as links in a WP nav menu. There is some obvious reasons why something is bound to break when you have two things on a table and tie them together, only to kick out the legs that support them.

In my research on the possible reason this is able to break is there is most likely nothing in the wp_nav_menu code anywhere, where ever it would be needed, which does a check to see if a taxonomy exists, and if yes, are there terms which the menu has added.

I would imagine such a thing as this was done in the code. Since it is able to recognize custom taxonomies and post types, and allows for them to be used in the menus, there is definitely a check for taxonomy done somewhere at least. However, it may just be lacking that fallback function which provides some kind of emergency plan for when the shit hits the fan, and a once existing taxonomy or post type being used by the nav menu no long exists, and the world was about to end.

Why This Bug NEEDs Fixing

So this may not seem like too big a deal so far. However, I have found this bug/thing to be a bit more of a serious issue given the fact that once you have gone and changed your taxonomy and initiated the error, there is no going back.

What I Tried and Learned Is Not A Fix For It

  • Remaking the taxonomy which was changed causing it to break. Even the previously used tax being made again had no effect in fixing the errors.
  • several different queries
  • rewriting the codes
  • rebuilding each item from scratch again (taxonomy, terms, nav menu hierarchy of terms
  • physically deleting each mention of the taxonomy, terms of it from within phpmyadmin
  • among other things...

I did spend about 6 hours or so of the day trying to figure out what the hell I could've done to f*ck it all up. I didn't see the obvious reason it happened in the first place. As usual, it was my super-human doing that caused it all by removing an apparently more crucial thing that I had thought.

Forced To Reset WordPress To Defaults To Fix

I couldn't find any other way that didn't require such drastic actions as completely resetting the site. I wish I could've, too. I mean, I had do reset everything back up TWICE! That was like 20 minutes wasted each time just doing that whole process both times.

Has this happened to you yet

I'd like to know whether I'm the only awesomely sexy and lucky person who has had the joy of stressing out to the wonders this creates, breaking your site. Have you ever had anything in WordPress 3.0 break that was as major as the entire menu system? Post comments!!

UPDATE: I've broken my WAMP WordPress menu system for a third time. Meaning I now have to reset the whole thing AGAIN :(

Shortlink:

Get automatic updates! Subscribe to Our RSS Feed or Get Email Updates sent straight to your inbox!

About the Author

Jared is from Boston working as a web and graphic designer. Also owns the design blog Tweeaks.com, and has designed many other websites powered by Wordpress including the New2WP theme.

Level: Rookie

User Comments

( ADD YOURS )

  1. Yes this seems to be a bug in the wordpress 3. Even I tried to rename the taxomony which was already been used i the menu item, then the menu option just breaks. I tried many things but could not fixed the problem but at last I renamed to the original name then it worked again. And one more thing, I have converted the wordpress to MU and the same theme's menu options works in one site and not in other. What is this going on? Is there any solution to this?

    Sanam


  2. Sorry, i d'ont speak english. But i search a solution for the identic Bug. I confirm, A big BUG after a modification with taxinomy + wp-nav..menu + wordpress 3 :s


  3. Yes, it is being worked on I found out and should hopefully be included when they release version 3.01, but at the very least it will be included in 3.1. Though 3.1 is not set to be finished until later on this year, but sometime before the end of the year so I've heard.

    I do know that there have been fixes to it made, but none that have been released to my knowledge.


  4. I had an issue with taxonomis too. In my case changing taxonomy settings using the Easy Post Types plugin. My entire site would only display on a long URL (two directories deep) based on a custom post type I had created.

    It was an absurd error and stumped everyone who helped. I finally had to do a fresh install of my entire site. Luckily, I had only invested a small amount of time j. The site before this happened. In the end I spent about 8hours on the problem and about an hour or 90 minutes on the reinstall. :-/

    Custom taxonomies are a delicious idea, but maybe not ready? What are everyone's experiences so far?

    -@JoshuaGuffey
    @JoshuaGuffey recently posted..What about when big changes hit Twitter


  5. Thanks for sharing Jared! I like the roach picture too. lol
    BoxedinDesign recently posted..Making a Twitter Background


  6. @Joshua You should get the WordPress reset plugin: http://sivel.net/wordpress/wordpress-reset/

    That's what I used to just easily reset my site to the defaults. All your plugins and themes still exist, just back up posts and the database, and you can import it after. But it's the best way to just revert to a fresh install. It will be hopefully not as needed, for things like this at least, once 3.1 is released.


  7. Ran into the same thing, looks like they're already aware of it:

    http://core.trac.wordpress.org/ticket/13958
    http://core.trac.wordpress.org/ticket/14181
    Chris Robinson recently posted..Freebie! Vector iPhone 4


  8. Yeah. I believe there has already been a patch made for it and will be in 3.1 release.


  9. Oh btw, I did link to both of those tickets in the first paragraph of this post. I submitted one of them myself.


  10. Fixed it!

    Go into phpMyAdmin -> wp_term_taxonomy -> Delete all references to the offending taxonomy -> go to functions.php and change the taxonomy back to its original form/name -> save functions.php -> nav-menus.php should work now... at least it did for me, thank the gods.


  11. Yeah you could do that, or you could just update WordPress to 3.0.1 version. This bug has been fixed in that version. :)


  12. Funny you mention that it's fixed. I'm running 3.0.1, but definitely had that same exact error and the only way I got it running again was by deleting those rows from the db.

    Anyway, Thanks for the post. Definitely set me on the right path.


  13. hmmm well maybe it is fixed in 3.1 then. I know they created a patch that fixed it, and it was added to the WP trunk shortly after I wrote this post. But I forget if it was a 3.1 patch. 3.0.1 was released after this, I know. So I figured it had the fix, but maybe not.


  14. I've the latest version of wordpress.
    I'm working on a site right now and have the same error.
    But this error came when after I've change the theme for a try.
    On the first them I had a custom menu.
    On the new one nope.
    And when I want to custom a menu the error appears.
    Can't fix it at the time.


  15. F*CK YEA @JACOB Nov2 it worked freaking AAAAAAAA


  16. Ill chime in here

    Thank you Jacob that worked a treat, I actually just deleted the DB entry in the phpmyadmin and that was fine, I didnt find any reference in the function.php file

    However I had been testing menus with new themes before buying my new one which I am just about to implement.

    Hope that helps.


  17. Just wanted to add that 3.1 did not fix the problem. I am running 3.1 with custom post types and taxonomies in the menu in a custom theme. Menu still working on the site but I no longer have access to the menu admin. All that shows up is a mostly white screen with the following error:

    Catchable fatal error: Object of class WP_Error could not be converted to string in .../wp-includes/formatting.php on line 445


  18. I'm pretty sure this was fix in 3.0.1 or 3.0.2 back in like August. I could be wrong, it stopped following the progress of the trac tickets for the bug, but I seem to remember reading something that said it was indeed fixed.

    The error you're getting is within the function check_invalid_utf8(), here: http://core.trac.wordpress.org/browser/trunk/wp-includes/formatting.php#L445

    437 /**
    436 * Checks for invalid UTF8 in a string.
    437 *
    438 * @since 2.8
    439 *
    440 * @param string $string The text which is to be checked.
    441 * @param boolean $strip Optional. Whether to attempt to strip out invalid UTF8. Default is false.
    442 * @return string The checked text.
    443 */
    444 function wp_check_invalid_utf8( $string, $strip = false ) {
    445 $string = (string) $string;
    446
    447 if ( 0 === strlen( $string ) ) {
    448 return '';
    449 }
    ............

    It appears that you're theme or some file somewhere on your site that you've created has an invalid charset.

    I usually get the error "Object of class WP_Error could not be converted to string" when I forget to close one of the parenthesis or curly braces. Check that you have no syntax errors and that your files/theme/etc are utf8.

    I know for a fact that this error you're getting has nothing to do with the subject of this post. That I am sure of.

    I'd say try Googling "Object of class WP_Error could not be converted to string" and see what you can find.


  19. Seems like I ran into a problem with trying to rename or remove a custom post type without first removing it from the WP menu.

    Also, FYI, if you have a custom taxonomy which has a capital letter in it's name, you will get an error when trying to add it to a WP menu.


  20. I just stumbled across this site as I was experiencing the same problem - errors after changing custom taxonomies that where used in a custom menu. Fortunately I found a way to fix this: Access your mySQL DB as the custom menus informations have been spread across the following categories:
    Menu Name: wp_term
    Menu Type: wp_term_taxonomy
    Menu Items: wp_posts
    I deleted my custom menu in the wp_tem and wp_posts tables and everything works again, I just needed to setup a new menu - which uses taxonomies I will never ever change again! :-)


  21. you shouldn't have to worry about it as of 3.0.2 I believe. 3.1 for sure has a fix for this, it was last summer when it was a major bug the WP core team was working to fix. So it should be ok if you decide to change tax or cpt names now lol. but i know what you mean, i wouldn't/haven't done it again since i found this bug.


  22. I'm on 3.1 and experiencing this fault after removing tumblog by woothemes. Not sure how I'm going to address yet. not looking forward to a rebuild.


  23. had the same problem.. just went in phpmyadmin > wp_term_taxonomy > deleted entries with the taxonomy -> nav_menu ...


  24. Hey this bug is still not fixed in 3.2 beta. Can someone tell me when is this bug gonna be fixed.

  1. Avatar

    Your Name
    February 4


    CommentLuv badge