WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 15 months ago

#42335 closed defect (bug) (duplicate)

NULL get_queried_object on /feed URL

Reported by: krbvroc1 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.9
Component: Query Keywords: has-patch
Focuses: Cc:

Description

I have been trying to track down numerous PHP notices littering my log files. I have traced it to when someone fetches a /feed version of a page/post. When this happens the various conditionals such as is_singular(), is_single(), is_page(), etc call

$post_obj = $this->get_queried_object();

which returns NULL. Then the WP routines try to reference the post_type which throws a notice such as:
PHP Notice: Trying to get property of non-object in /opt/www/wp-includes/class-wp-query.php on line 3895

Woocommerce for example uses template_redirect and checks is_page() or is_singular() which throws a bunch of notices.

WP_Query does have an is_feed variable that is set...perhaps it could use that as a check before it tries to access a null object.

Attachments (1)

42335.diff (9.4 KB) - added by munyagu 2 years ago.
Add check return value from get_queried_object()

Download all attachments as: .zip

Change History (3)

@munyagu
2 years ago

Add check return value from get_queried_object()

#1 @munyagu
2 years ago

  • Keywords has-patch added

I added a check to the following methods.

WP_Query::is_attachment()
WP_Query::is_author()
WP_Query::is_category()
WP_Query::is_page()
WP_Query::is_single()
WP_Query::is_singular()
WP_Query::is_tag()
WP_Query::is_tax()

#2 @SergeyBiryukov
15 months ago

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

Hi there, welcome to WordPress Trac!

Thanks for the report, we're already tracking this issue in #29660.

Note: See TracTickets for help on using tickets.