wordpress出现Catchable fatal error: Object of class WP_Error could not be converted to string的解决办法

偶然查看附件页面的时候出现“Catchable fatal error: Object of class WP_Error could not be converted to string”(致命错误:对象的类WP_Error不能转换为字符串)的错误。

Catchable fatal error: Object of class WP_Error could not be converted to string

原因:

This happens i understand because of custom post types or custom category types and is likely because an instance of a category ID is empty.(发生这种情况我理解因为定制的帖子类型或自定义类别类型和可能是因为一个类别的实例ID是空的。)

解决方法:

方法1、参考网站

找到:

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

修改为:

echo is_wp_error( $cat_parents = get_category_parents($cat, TRUE, '' . $delimiter . '') ) ? '' : $cat_parents;>

方法2、参考网站

<?php $categories = get_the_category(); echo (get_category_parents($categories[0]->term_id, TRUE, ' &gt; '));  ?>

改成:

<?php $categories = get_the_category(); echo intval((get_category_parents($categories[0]->term_id, TRUE, ' &gt; ')));  ?>

就ok啦,就是把echo部分的字符类转换为整数就可以啦。

遇到类似的错误都可以尝试用这个方法解决!