• Hi– I’m using a custom theme and whenever I try to view a post I get this error: Catchable fatal error: Object of class WP_Error could not be converted to string in line 144.

    Based on all of the other posts I’ve read, it seems like this error is usually the result of deleting categories. Makes sense, I had deleted a few right before this problem started. I’m working with the theme developer and changed line 143 from this:

    $cat_tree = get_category_parents($category[0]->term_id, FALSE, ':', TRUE);

    to

    is_wp_error($cat_tree = get_category_parents($category[0]->term_id, FALSE, ':', TRUE)) ? '' : $cat_tree;

    with no luck, and also tried changing 144 to this:

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

    to

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

    Any other suggestions? Thank you people of wordpress!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The problem is a function return value is being assigned to a variable. Then this variable is being treated like a string when it is actually an object. The correct way to handle this is to do a check for the error before continuing.

    $cat_tree = get_category_parents($category[0]->term_id, FALSE, ':', TRUE);
    if ( is_wp_error( $cat_tree ) )
          return;  //Or do further error handling
    Thread Starter TeleportMASSIV

    (@teleportmassiv)

    Thanks for the response. I’m just getting my feet wet some I’m not sure how to check for the error with that code.

    The theme’s support team is suggesting that it’s a problem with my wordpress installation, so I’m setting up a test WP installation site with the theme installed on a blank database which seems like it will obviously work, I suppose to rule out some things.

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