Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#56354 closed defect (bug) (duplicate)

With PHP 8.0.x, WordPress class-wp-query.php core file throws "Attempt to read property “post_type” on null"

Reported by: deksar's profile deksar Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.0
Component: Query Keywords: needs-patch
Focuses: Cc:

Description

I got the following PHP warning (on PHP 8.0.20), I have no idea what to do but my error_log file is getting extremely filled with this.

“Attempt to read property “post_type” on null in <b>/home/xx/public_html/wp-includes/class-wp-query.php</b> on line 4338 on any URL ending with mysite.com/category/feed/

(feed displays, however the error is at the top of the page)

I’ve searched for that warning message on Google and I can say there’re thousands (no joke) of websites indexed with that warning message in the results.

So, it seems that’s a very common WordPress problem.

The warning appears only in /feed/ pages, the mentioned line in class-wp-query.php file contains:
"return in_array( $post_obj->post_type, (array) $post_types, true );"

Wordpress version: 6.0.1

Just wanted to report it as there're thousands of websites with the same results on Google, and while it's not generated by any plugin but a WordPress core file itself.

And it seems this one happens only when having PHP version 8.0.

Change History (2)

#2 @costdev
2 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi @deksar, thanks for opening this ticket!

We're already tracking this issue in #29660. Let's continue the discussion there.

P.S. As part of anti-spam efforts, I have also removed your comment linking to various websites as examples of the warning.

#3 @costdev
2 years ago

  • Component changed from General to Query
Note: See TracTickets for help on using tickets.