Make WordPress Core

Opened 5 years ago

Closed 5 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:


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, ' &raquo; '); ?>

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)

#1 @nacin
5 years ago

  • Keywords reporter-feedback added; dev-feedback removed

What's $cat?

#2 @ocean90
5 years ago

You get this message because the cat id doesn't exist. I could reproduce it with 3.0.3 too.

#3 @tar.gz
5 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:

 if ( is_single() ) { 
 $cat = get_the_category(); $cat = $cat[0];
 echo(get_category_parents($cat, TRUE, ' &gt; ')); }

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.

#4 @nacin
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Indeed, get_the_category currently doesn't return ordered numeric indexes.

Closing as a duplicate of #15442.

Note: See TracTickets for help on using tickets.