【问题标题】:get_term_link throws WP_ERRORget_term_link 抛出 WP_ERROR
【发布时间】:2018-08-18 01:19:35
【问题描述】:

我正在使用 get_term_link 检索术语链接并在 href(链接)中回显它。

它可以在网站上运行,但是当我抓取网站时,它throws the status code 500
当它出现在服务器上的 php_errors.log 中时,我发现了这一点。

错误:PHP 可捕获的致命错误:WP_Error 类的对象无法 在..etc/etc/中转换为字符串

$get_term = get_term_by('slug', 'term', 'taxonomy');
$link = get_term_link($get_term->term_id, 'taxonomy'); 

如何避免这个抓取问题?非常感谢您的反馈,谢谢

【问题讨论】:

  • 将所有代码放入您的问题中。我们无法猜测为什么会出现错误

标签: php wordpress fatal-error taxonomy


【解决方案1】:

请检查此网址。 https://developer.wordpress.org/reference/functions/get_term_link/#return

(string|WP_Error) HTML link to taxonomy term archive on success, WP_Error if term does not exist.

get_term_link() 函数返回 (string|WP_Error)。

因为您提供了一点代码。这是我可能的解决方案。

  • get_term_link() 第一个参数不仅接受 term id 还接受 term 对象。 所以我建议改变 这个

    $link = get_term_link($get_term->term_id, 'taxonomy'); 
    

    $link = get_term_link($get_term, 'taxonomy'); 
    
  • 检查此函数是否返回准确值。

    $get_term = get_term_by('slug', 'term', 'taxonomy');
    

希望这些帮助。

谢谢

【讨论】:

    猜你喜欢
    • 2018-10-12
    • 2017-02-06
    • 1970-01-01
    • 2019-04-19
    • 1970-01-01
    • 1970-01-01
    • 2015-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多