WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#26775 closed defect (bug) (fixed)

Fatal error in wp_reset_postdata()

Reported by: SergeyBiryukov Owned by: SergeyBiryukov
Milestone: 3.8.1 Priority: normal
Severity: normal Version: 3.7
Component: Query Keywords: has-patch needs-unit-tests fixed-major
Focuses: Cc:

Description

[25601] introduced a fatal error when calling wp_reset_query() or wp_reset_postdata() without a valid $wp_query global:

Fatal error: Call to a member function reset_postdata() on a non-object in wp-includes/query.php on line 118

We should probably add a _doing_it_wrong() message in there, but at least let's fix the fatal error.

Attachments (1)

26775.patch (384 bytes) - added by SergeyBiryukov 4 years ago.

Download all attachments as: .zip

Change History (8)

#1 @SergeyBiryukov
4 years ago

26775.patch uses a basic isset() check, like the ones we already have for template tags: tags/3.8/src/wp-includes/query.php#L139

#2 @nacin
4 years ago

  • Milestone changed from 3.9 to 3.8.1

#3 @nacin
4 years ago

This looks good.

#4 @SergeyBiryukov
4 years ago

  • Keywords fixed-major added
  • Owner set to SergeyBiryukov
  • Status changed from new to accepted

Fixed for trunk in [26932].

#5 @nacin
4 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 26951:

Avoid a fatal error in wp_reset_postdata() if $wp_query global is not set.

Merges [25932] to the 3.9 branch.

props SergeyBiryukov.
fixes #26775.

#6 @kovshenin
4 years ago

In [26951] Nacin meant the 3.8 branch, not 3.9.

#7 @nacin
4 years ago

Indeed.

Note: See TracTickets for help on using tickets.