1

I am getting these PHP8.0 Warnings from my WordPress site. The warnings are pointing to core code, not anything custom. When I turn debugging on there are no error messages on the site. I also checked the menu and all of the links are accurate. Is anyone able to help me figure out this warning?

[09-Jan-2024 19:21:27 UTC] PHP Warning:  Attempt to read property "ID" on null in \wp-includes\post-template.php on line 674

[09-Jan-2024 19:21:27 UTC] PHP Warning:  Attempt to read property "post_type" on null in \wp-includes\post-template.php on line 675
    if ( is_singular() ) {
        $post      = $wp_query->get_queried_object();
        $post_id   = $post->ID; // Line 674
        $post_type = $post->post_type; // Line 675
2
  • 1
    For some reason the $post variable is missing on a single post template. Does this error appear on particular pages? Are you doing anything unusual in custom code that would affect the $post variable? Are you creating some kind of custom route/endpoint that doesn't point to a post? Commented Jan 10 at 4:25
  • Ah, it seems the error was showing when you get the 404 error message. I created a custom 404 error page and the error is now gone. Thank you for pointing me in the right direction!
    – Dawn
    Commented Jan 10 at 18:19

1 Answer 1

1

The error was occurring when someone hits a page that doesn't exist (404). I created a custom 404 error page and the errors are now gone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.