Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I get this error in my theme:

Catchable fatal error: Object of class WP_Error could not be converted to string in /home/winentra/public_html/s1.ssonline.co.in/wp-content/themes/peekaboo/admin/common-functions.php on line 186

Line No. 186:

echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');

Context:

 elseif ( is_single() ) {
          $cat = get_the_category(); 
              $cat = $cat[0];
          echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
          echo $currentBefore;
          the_title();
          echo $currentAfter;
}

Any ideas on this please?

share|improve this question
add comment

1 Answer 1

If you call get_the_category() without a parameter you have to use it in a loop – after the_post(); was called. Otherwise get_the_category() returns FALSE and get_category_parents() returns a WP_Error object … which is lacking a toString() method and therefore cannot be printed.

So test if you get an object or a string before you try to echo the return value.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.