I have a two PHP Notices at one of my project – “Trying to get property of non-object”
I know whats that means (more or less), but the problem is i can’t find which code element make this notice… this drive me crazy…
- Trying to get property of non-object in /xxxxxxxxxxxx/wp-includes/class-wp-query.php on line 3871
( At github is here -> https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-query.php#L4029 )
- Trying to get property of non-object in /xxxxxxxxxxxxxx/wp-includes/link-template.php on line 643
( At github is here -> https://github.com/WordPress/WordPress/blob/master/wp-includes/link-template.php#L673 )
In this project i used:
- My own template
- Woocommerce plugin (latest release)
- ACF (latest release)
- Yoast SEO (latest release)
Maybe is something wrong with my custom query?
For example this is what i use:
' https://pastebin.com/YEBQAXgs '
The question is: how can i find/catch this notice and figure which part of my code should i correct?
2
Answers
With what you posted, it’s probably a Symptom of an invalid sql query. If you try to prepare bad sql, it won’t generate a statement object which will lead to that error.
It comes from Woocommerce wc_prevent_adjacent_posts_rel_link_wp_head function which is actioned by the template_redirect hook.
It does a call to is_singular(‘product’) which gets the queried object and if the query is for a feed it comes back NULL and therefore is not an object.