Support » Themes and Templates » Catchable fatal error: Object of class WP_Error could not be converted to string

  • I think the error began occurring after I deleted a few unused tags:

    Catchable fatal error: Object of class WP_Error could not be converted to string in / on line 348

    According to Dreamweaver, 348 is this:
    cho get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');

    Surrounding it is this:

    $post_type->labels->singular_name . '</a> ' . $delimiter . ' ';
            echo $before . get_the_title() . $after;
          } else {
            $cat = get_the_category(); $cat = $cat[0];
    <strong>        echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');</strong>
            echo $before . get_the_title() . $after;

    I have no idea how to fix this. Can anyone throw me a bone?

Viewing 15 replies - 1 through 15 (of 16 total)
  • Try uploading a fresh copy of the theme to wp-content/themes using FTPe (or whatever file management application your host provides).


    Uploading a fresh copy of the theme did not fix the problem.

    Do you have any other suggestions?


    It’s definitely a theme-specific problem. Installing another theme fixes the problem.

    I have been getting so fed up with people finding answers and not coming back I thought I would come back on this one have taken 48hours to find an answer.

    This happens i understand because of custom post types or custom category types and is likely because an instance of a category ID is empty.

    I found changing:

    echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');


    echo is_wp_error( $cat_parents = get_category_parents($cat, TRUE, '' . $delimiter . '') ) ? '' : $cat_parents;

    fixed all my issues with the “Catchable fatal error: Object of class WP_Error could not be converted to string”

    macmend! Thank YOU.

    That fixed the “Catchable Error” I was having in a custom built theme. I believe you are correct in the idea that the category type was deleted.

    That line of code makes all the difference.

    Thank you for contributing.

    Thanks for this post. This corrected issues I was having with a purchased theme (that I really like) and the WPSC (store) plugin. I was getting it when looking at single products when clicked for additional details. It was definitely a problem with the category, as it would change the page from its proper parent.

    This fixed my issue and I’m so happy to use both my theme and this plugin still


    Big help.

    That worked greatly for me!

    Thanks macmend!!!

    Just had this problem and just tried the “fix.” Solved the problem.

    Is this a deprecated way of assigning that or what exactly is incorrect with the original code? Just wondering so I can let the theme developer know… and to avoid ever using that theme developer again.

    I’m getting a similar error when I try to access posts:

    Catchable fatal error: Object of class WP_Error could not be converted to string in /home/ryebrew/ on line 144

    Although it’s not a functions.php problem, it seems similar to me since it started after I deleted some categories. The problem code is:

    $top_cat = split(':',$cat_tree);

    and it’s around

    <?php // get parent category
    						if(get_post_type() == 'post') {
    							$category = get_the_category();
    							$cat_tree = get_category_parents($category[0]->term_id, FALSE, ':', TRUE);
    							$top_cat = split(':',$cat_tree);
    							$parentObj = get_category_by_slug($top_cat[0]);
    							$parent = $parentObj->name;
    							$cat_link = get_category_link($parentObj->term_id);
    						} else {
    							$parent = "";

    Any help would be hugely appreciated.

    macmend you are a God, you know that right haha
    worked for me, saved my butt. thanks a million. You rock.
    And I always follow up with the solution because it’s just what you do. 😉

    A simple solution if you are getting this error is to make sure your custom post type is attached to at least 1 category or taxonomy.

    This error occurs when you make a post that has no category if your code is using get_category_parents

    I’m getting this problem, where I get the PHP error reported by jamieskella.
    It’s related to one single post. Accessing that one post causes the PHP error, and nothing renders in the page after the first part of the breadcrumbs code.

    The PHP error points to a line referring to the “get_category_parents” function in the dimox_breadcrumbs() function in the theme’s functions.php

    I found on a hunch that if I changed the offending post’s permalink name, the whole page would suddenly render OK again.

    Because the search engines wouldn’t find my old permalink, I set up a 301 redirect in my .htaccess file so that requests for the old permalink would get redirected to the new one. But of course really I’d like to use the permalink I choose – the “old” one.

    Unfortunately jonathan’s fix didn’t work for me.

    Without exhaustive searching, I can’t be sure that the problem isn’t happening on other posts, and of course I’d like to be able to use the permalink name that I choose.

    What can be possibly causing the page to stop rendering unless I edit the permalink name?



    Jonathan solution is very good, thank so much! But I have another problem, After successful fix that error, the page show up but there no button to “post” like this box, it;s show everything except the submit button.

    Moderator Andrew Nevins


    WCLDN 2018 Contributor | Volunteer support

    If you’re not contributing to the original poster, create your own thread on the issue.



    Pls note that that
    get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
    is intended to return the parent categories of category pages not posts!
    When using in posts you have to get the category id first and then pass the value over to the function.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Catchable fatal error: Object of class WP_Error could not be converted to string’ is closed to new replies.