Catchable fatal error: Object of class WP_Error could not be converted to string - How to Fix

Permalink e URL semantiche su Wordpress con IIS

On 11 June 2017 this website experienced a serious downtime that was caused by a very odd error occurred within the WordPress database. If you've stumbled upon this post, chances are you might be affected by the same issue.

The issue looked like a standard HTTP 500 - Application Error that blocked any non-cached page. As usual, the first thing I did to read the actual error was to enable the WP_DEBUG and WP_DEBUG_LOG switches within the wp-config.php file, which - as you most certainly know - is located inside the WordPress installation root folder:

As we can read in the above comments, the first of these switches shows the error within the HTTP response, while the latter writes it into a dedicated debug.log file.

Anyway, this is the actual error:

Catchable fatal error: Object of class WP_Error could not be converted to string in /var/www/ryadel.com\wp-includes\rewrite.php on line 326

Sadly, the given info were not enough to shred much light. I briefly took a look to the rewrite.php source code, finding the following function (line 326 is the highlighted one):

Nonetheless, that was enough to understand something about the underlying problem was about: the code looking for a category name and finding a WP_Error object instead.

The next thing i did was taking a look to the PHP error log. There i found a confirmation of the above error and also some interesting info that greatly helped me to understand what actually happened:

The picture was taking form: the root cause was most likely a I/O permission issue which resulted into a WP_Error object being wrote into a MySQL table instead of the expected category name. Although I couldn't determine if this was a WordPress code issue or a MySQL issue, all the clues led to the former (Worpdress build was the 4.8, which was released only a couple days before the issue).

A quick filtered search using SQLyog (if you don't know what it is, read here) helped me to find where the offending value actually was: the category_base option within the wp_options table.

Here's how the key/value looked like:

Catchable fatal error: Object of class WP_Error could not be converted to string - How to Fix

Once the issue was figured out, the fix was really simple: deleting all the content within the category_base key and leaving it empty actually did the trick, bringing the website back up.

Catchable fatal error: Object of class WP_Error could not be converted to string - How to Fix

That's about it. In case you happen to experience this issue, now you know how to overcome it for good.

 

 

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

6 Comments on “Catchable fatal error: Object of class WP_Error could not be converted to string - How to Fix”

  1. I’m getting something similar https://wordpress.stackexchange.com/questions/326241/recoverable-fatal-error-object-of-class-wp-error-could-not-be-converted-to-stri

    But I’m not sure where to check for the PHP error log? The site was moved from Bluehost to Dreamhost using duplicator which might be related.

  2. Hi, the solution works for me. I tried hard all day, changing PHP version, upgrading…downgrading all day…thank you..

  3. Hi. This solution worked for me, but the next day, content was back in the catgory_base key.

    Site went back down and I had to delete again.

    Is there a permanent fix for this?

    1. Have you upgraded WP to the latest version? I’ve never seen this happening in a while, thought they fixed it after 4.8.

  4. Hi Ryan,

    This solution didn’t work for me. I’m still getting an error.
    Could you please help me?

    Error: Recoverable fatal error: Object of class WP_Error could not be converted to string in /home2/nbmbaaaustin/public_html/wp-content/themes/eventchamp/include/speaker-modules.php on line 256

    website url: https://hbcubattleofthebrains.com/speaker/dasha-smith/?fbclid=IwAR3IJlSk8zTEGr8jFkGrx5OISo4aNP78U8b5wu3YOLag4jA4L5nEL7OPjyc

    Thanks a lot in advance for your time and help.

    Kr,
    Christopher

    1. You’re only halfway done with your debug job: now you need to take a look at the speaker-modules.php file and understand which DB row/column of the WP_OPTIONS table you need to fix.

      Do that (or have a programmer do that) to fix your issue for good: I’m afraid you won’t be able to fix that without involving some minimal PHP programming knowledge.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.