【问题标题】:how to fix "Object of class WP_Error could not be converted to string" error in wordpress如何修复wordpress中的“WP_Error类的对象无法转换为字符串”错误
【发布时间】:2019-09-28 01:17:32
【问题描述】:

我的 wordpress 主题有些问题。 我的 wordpress 错误是:

可捕获的致命错误:WP_Error 类的对象无法在 C:\wamp64\www\sanat\wp-content\themes\shokoohsanat\includes\ninzio-functions.php 中的第 472 行转换为字符串

nizino-function.php 中的第 472 行:

echo '<a href="'.$first_term_link.'">'. $first_term->name .'</a>';

nizino-function.php 中的第 473 行:

echo $text_before.get_the_title().$text_after;

PHP7。我已经检查了 Wordpress 版本 4.7.13 和 5.2 和 5.1

【问题讨论】:

  • 由于您的消息错误,您正在使用 WP_Error 类并尝试将其转换为字符串。所以你得到这个错误。让我们在文件 ninzio-functions.php 中发布完整的代码。或者你可以在codex.wordpress.org/Class_Reference/WP_Error查看WP_Error的信息
  • 我在这里上传了一部分代码:mertaa.ir/php-Error.txt。我无法用文档修复它。我不是专业人士。请帮帮我...
  • 您是否删除了代码行 472 和 473,它运行成功?

标签: php html wordpress


【解决方案1】:

将第 472 行替换为:

if ( is_wp_error( $first_term ) ) {
    echo 'No terms found';
} else {
    echo '<a href="'.$first_term_link.'">'. $first_term->name .'</a>';
}

【讨论】:

    猜你喜欢
    • 2012-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-15
    • 1970-01-01
    • 2013-07-03
    相关资源
    最近更新 更多