php - 试图在 wordpress 中获取非对象“class-wp-query.php”和“link-template.php”的属性
问题描述
我的一个项目中有两个 PHP 通知 - “尝试获取非对象的属性”
我知道这意味着什么(或多或少),但问题是我找不到哪个代码元素发出这个通知......这让我发疯......
- 试图在第 3871 行的 /xxxxxxxxxxxx/wp-includes/class-wp-query.php中获取非对象的属性
(在 github 在这里 -> https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-query.php#L4029)
- 试图在第 643 行的 /xxxxxxxxxxxxxx/wp-includes/link-template.php中获取非对象的属性
(在 github 在这里 -> https://github.com/WordPress/WordPress/blob/master/wp-includes/link-template.php#L673)
在这个项目中,我使用了:
- 我自己的模板
- Woocommerce 插件(最新版本)
- ACF(最新版本)
- Yoast SEO(最新版本)
也许我的自定义查询有问题?例如这是我使用的:
' https://pastebin.com/YEBQAXgs '
问题是:我怎样才能找到/抓住这个通知并确定我应该更正我的代码的哪一部分?
解决方案
它来自 Woocommerce wc_prevent_adjacent_posts_rel_link_wp_head 函数,该函数由 template_redirect 钩子执行。
它调用 is_singular('product') 来获取查询的对象,如果查询是针对提要的,则返回 NULL,因此不是对象。
推荐阅读
- javascript - 通过重叠颜色在javascript中隐藏和可见的表面渲染
- .htaccess - 特定 URL 重定向到主页
- html - flexbox 容器内的 Divs 动画
- php - 创建多维数组,并处理 json_encode 的相同键名问题
- c++ - 链接 DLL 后空 QT GUI 崩溃
- javascript - JavaScript:如何在执行条件的特定持续时间后清除间隔
- python-3.x - Matplotlib 故障 [python3]
- laravel - laravel 会在返回的模型集合的任何位置重新连接到数据库吗?
- javascript - 过滤在 vue.js 上的计算属性中定义的结果的函数的问题
- shell - 如何用 awk 处理最后一个命令的结果?