Catchable fatal error: Object of class WP_Error could not be converted to string
-
Hey guys,
I’m just adding the finishing touches to my new wordpress site. I decided that I wanted to have breadcrumbs on my portfolio pages to help distinguish which sub category each entry was in.
I was using the get_category_parents function to create breadcrumbs.
This worked fine in category.phpWhen I decided to add it to the single.php file, as I thought it would be a nice addition, I received the following error:
Catchable fatal error: Object of class WP_Error could not be converted to string in D:\wamp\www\bms-wp\wp-includes\category-template.php on line 70
I managed to narrow down the issue to the get_category_parents function in category-template.php. Something very very strange occurs in amongst the code.
On line 69, there is a conditional statement to test whether or not to produce a link on the category.
if ( $link ){ $chain .= '<a href="' . get_category_link( $parent->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $parent->cat_name ) ) . '">'.$name.'</a>' . $separator; } else { $chain .= $name.$separator; }
If I add the following code just after the
if($link){
line:print_r($parent); die( $parent->term_id);
and call the function on a page that uses single.php, nothing is output to the browser. If I request the a page using category.php, it outputs the
$parent
object, and also the$parent->term_id
.To make it more confusing, if put this same code just above the conditional statement, it displays fine for single.php. If I save it to a variable, then try to use that variable instead of any reference to $parent inside the conditional, the same error occurs.
It is as if the object just vanishes into thin air inside that conditional. If I put the whole line inside the
if($link){ ... }
conditional just before it, though it doesn’t output correctly for code that requires no link, it outputs without the error.If I disable all plugins, the issue still occurs. If I disable custom permalinks, the issue resolves. I am using WAMP 2.0i as a local development server. I tried updating the PHP version from 5.3.0 to 5.3.1, and the issue still persists.
I have been using PHP for a while, and I don’t know whether this is a bug with PHP, because I didn’t know permalinks could have anything to do with a PHP object vanishing like this. This has been causing me some serious headaches; I can live without the breadcrumbs but I would much much rather get the issue resolved, so any help is very appreciated.
- The topic ‘Catchable fatal error: Object of class WP_Error could not be converted to string’ is closed to new replies.