Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#28412 closed defect (bug) (fixed)

get_queried_object_id() method in pre_get_posts

Reported by: wpsmith's profile wpsmith Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 4.0 Priority: normal
Severity: normal Version: 4.0
Component: Query Keywords: has-patch dev-feedback
Focuses: Cc:


When using $wp_query->get_queried_object_id() within the pre_get_posts hook results in an error:
Notice: Undefined property: WP_Query::$post in C:\xampp\htdocs\wp\wp-includes\query.php on line 3700

Here is a simple test:

Attachments (2)

28412.patch (661 bytes) - added by wpsmith 10 years ago.
query.php patch
28412.diff (437 bytes) - added by kovshenin 10 years ago.

Download all attachments as: .zip

Change History (7)

10 years ago

query.php patch

#1 @wpsmith
10 years ago

  • Keywords has-patch dev-feedback added

This ticket was mentioned in IRC in #wordpress-dev by wpsmith. View the logs.

10 years ago

#3 @SergeyBiryukov
10 years ago

  • Focuses administration template multisite performance removed
  • Milestone changed from Awaiting Review to 4.0

10 years ago

#4 @kovshenin
10 years ago

An alternative approach in 28412.diff: since we're checking for null with is_null(), let's actually set it to null during init.

#5 @SergeyBiryukov
10 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 28667:

Avoid a PHP notice when using WP_Query::get_queried_object() in pre_get_posts action.

props wpsmith.
fixes #28412.

Note: See TracTickets for help on using tickets.