WordPress.org

Ready to get started?Download WordPress

Forums

Catchable fatal error: Object of class WP_Error could not be converted to string (17 posts)

  1. jamieskella
    Member
    Posted 2 years ago #

    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 /brisbanebite.com.au/wp-content/themes/foodpress/functions.php 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?

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Try uploading a fresh copy of the theme to wp-content/themes using FTPe (or whatever file management application your host provides).

  3. jamieskella
    Member
    Posted 2 years ago #

    Hi,

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

    Do you have any other suggestions?

    Jamie

  4. jamieskella
    Member
    Posted 2 years ago #

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

  5. jonathan (previously known as macmend) spencer
    Member
    Posted 2 years ago #

    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 . ' ');

    to

    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"

  6. jessicarudden
    Member
    Posted 2 years ago #

    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.

  7. UIAJosh
    Member
    Posted 2 years ago #

    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

    :D

    Big help.

  8. abdul raja
    Member
    Posted 2 years ago #

    That worked greatly for me!

    Thanks macmend!!!

  9. cnymike
    Member
    Posted 1 year ago #

    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.

  10. TeleportMASSIV
    Member
    Posted 1 year ago #

    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/wedrinkyourbeer.com/wp-content/themes/Swagger-Theme/swagger/inc/single-normal.php 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 = "";
    							$cat_link="";

    Any help would be hugely appreciated.

  11. wbjtk
    Member
    Posted 1 year ago #

    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. ;)

  12. wycks
    Member
    Posted 1 year ago #

    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

  13. sadhaka
    Member
    Posted 1 year ago #

    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?

  14. nguyenkinh
    Member
    Posted 1 year ago #

    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.

  15. Andrew Nevins
    Spam zapper & Volunteer Moderator
    Posted 1 year ago #

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

  16. Neoras
    Member
    Posted 1 year ago #

    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.

  17. alvinCPweb
    Member
    Posted 1 year ago #

    Thank you so much! I was pulling my hair out until I found this post!

Topic Closed

This topic has been closed to new replies.

About this Topic