Opened 14 years ago
Closed 14 years ago
#15776 closed defect (bug) (duplicate)
get_category_parents produces fatal error
Reported by: | tar.gz | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.1 |
Component: | General | Keywords: | reporter-feedback |
Focuses: | Cc: |
Description
On a test install of WP 3.1 [16732], I notice that this function is broken: it produces an error when called inside the single post template.
Using this code :
<?php echo get_category_parents($cat, TRUE, ' » '); ?>
produces the following error message: Catchable fatal error: Object of class WP_Error could not be converted to string in (.../themes/twentyten/loop-single.php). This effects every post.
I did not spot this error in 3.1-beta1-16723, so I believe it has been introduced after that build.
To rule out any error in my custom theme, I tested it with the Twenty Ten 1.3-alpha theme, adding the function above inside loop-single.php (at line 32, just above the content). It produces the same error message.
Possibly related issue: #7030
Change History (4)
#2
@
14 years ago
You get this message because the cat id doesn't exist. I could reproduce it with 3.0.3 too.
#3
@
14 years ago
Thanks for the clarification. Indeed my testing was incomplete, $cat needs to be defined. The code that I am using successfully in 3.0.3 (in order to generate a breadcrumbs trail) looks like this:
<?php if ( is_single() ) { $cat = get_the_category(); $cat = $cat[0]; echo(get_category_parents($cat, TRUE, ' > ')); } ?>
The line that gets flagged in the error message is the line with echo(get_category_parents ... -- that's what brought me to believe that there was an issue with this function.
It might very well be that there is a conceptual flaw in my code, but it was working until now.
What's $cat?