WordPress.org

Ready to get started?Download WordPress

Forums

Catchable fatal error: Object of class WP_Error could not be converted to string (12 posts)

  1. Iyke Charles
    Member
    Posted 1 year ago #

    Catchable fatal error: Object of class WP_Error could not be converted to string in /home/ravensne/public_html/wp-content/themes/continuum/single.php on line 120

    Please i really do need your help on correcting this error and am new to wordpress and css...

    this is d line of code, from line 117 to 123

    <?php // get parent category
                                    $category = get_the_category();
                                    $cat_tree = get_category_parents($category[0]->term_id, FALSE, ':', TRUE);
                                    $top_cat = split(':',$cat_tree);
                                    $parentObj = get_category_by_slug($top_cat[0]);
                                    $parent = $parentObj->name;
                                    ?>

    I would really appreciate your help.

  2. Iyke Charles
    Member
    Posted 1 year ago #

    Line 120 is actually

    $top_cat = split(':',$cat_tree);
  3. esmi
    Forum Moderator
    Posted 1 year ago #

    I'd suggest checking what $cat_tree is actually returning by dumping that string to the screen.

  4. Iyke Charles
    Member
    Posted 1 year ago #

    pls how do i do that...
    am new to wordpress.
    thanks

  5. esmi
    Forum Moderator
    Posted 1 year ago #

    <?php // get parent category
    $category = get_the_category();
    $cat_tree = get_category_parents($category[0]->term_id, FALSE, ':', TRUE);
    echo $cat_tree;
    /*
    $top_cat = split(':',$cat_tree);
    $parentObj = get_category_by_slug($top_cat[0]);
    $parent = $parentObj->name;
    */
    ?>
  6. Iyke Charles
    Member
    Posted 1 year ago #

    it is still showing the same error...
    any other suggestion please.
    thanks

    [No bumping. If it's that urgent, consider hiring someone.]

  7. esmi
    Forum Moderator
    Posted 1 year ago #

    What output did you get for $cat_tree?

  8. Iyke Charles
    Member
    Posted 1 year ago #

    same out put...

    Catchable fatal error: Object of class WP_Error could not be converted to string in /home/ravensne/public_html/wp-content/themes/continuum/single.php on line 120

  9. esmi
    Forum Moderator
    Posted 1 year ago #

    In that case, you're getting an error because $cat_tree is empty - which suggests that you're trying to get the parents of a top-level category.

  10. Iyke Charles
    Member
    Posted 1 year ago #

    so how do i fix it now, sorry for the disturbance.

  11. esmi
    Forum Moderator
    Posted 1 year ago #

    Well, it might help if you described what you're using this code for and where.

  12. Iyke Charles
    Member
    Posted 1 year ago #

    when i check my uploaded files via my mobile theme, there are there but when i check them via my desk to theme i get his same error either am logged in or not.
    Catchable fatal error: Object of class WP_Error could not be converted to string in /home/ravensne/public_html/wp-content/themes/continuum/single.php on line 120.

    i just want my site to work fine...

Topic Closed

This topic has been closed to new replies.

About this Topic