首页 > 解决方案 > 试图在 wordpress 中获取非对象“class-wp-query.php”和“link-template.php”的属性

问题描述

我的一个项目中有两个 PHP 通知 - “尝试获取非对象的属性”

我知道这意味着什么(或多或少),但问题是我找不到哪个代码元素发出这个通知......这让我发疯......

  1. 试图在第 3871 行的 /xxxxxxxxxxxx/wp-includes/class-wp-query.php中获取非对象的属性

(在 github 在这里 -> https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-query.php#L4029

  1. 试图在第 643 行的 /xxxxxxxxxxxxxx/wp-includes/link-template.php中获取非对象的属性

(在 github 在这里 -> https://github.com/WordPress/WordPress/blob/master/wp-includes/link-template.php#L673

在这个项目中,我使用了:

也许我的自定义查询有问题?例如这是我使用的:

' https://pastebin.com/YEBQAXgs '

问题是:我怎样才能找到/抓住这个通知并确定我应该更正我的代码的哪一部分?

标签: phpwordpressnotice

解决方案


它来自 Woocommerce wc_prevent_adjacent_posts_rel_link_wp_head 函数,该函数由 template_redirect 钩子执行。

它调用 is_singular('product') 来获取查询的对象,如果查询是针对提要的,则返回 NULL,因此不是对象。


推荐阅读