When I upgraded to WordPress 2.7 I started getting the following error wherever I used the get_the_category() function in my WordPress themes.

Catchable fatal error: Object of class WP_Error could not be converted to string in /home/dcing/public_html/wp-content/themes/dcing/category.php on line 52

I thought I would be a common bug, and I can easily find a solution on Internet so I tried search. But I was not able to find a fix for that problem. So I self debugged the code and managed to sort out a solution. Here are the steps to fix the problem.

  1. Open wp-includes/category-template.php
  2. Search for “function get_category_link( $category_id ) {
  3. Now inside that function, search the following lines
    if ( is_wp_error( $category ) )
    return $category;
  4. Replace the above 2 lines with following code
    //if ( is_wp_error( $category ) )
    //return $category;

That should solve the problem. Enjoy WordPressing.

2 Comments

  • # 1
    April 15, 2009 at 5:10 pm

    Hi,

    Thanks for this information.
    Recently I had upgraded to wordpress 2.7.1, after which I started to face this problem.
    I found your solution after I search for this error. Now my problem is solved.
    Appreciated.

    SetShine.com

  • # 2
    May 9, 2009 at 4:01 pm

    If you check what is actually being returned by get_category() in get_category_link() you’ll see it is an error object (at least in WP 2.8-bleeding). The problem seems to be caused by telling get_category() to retrieve the cat_ID results from a get_category() call.

Leave a comment