skip to Main Content

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…

  1. 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 )

  1. 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


  1. 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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search