WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#21967 closed defect (bug) (fixed)

"Passed variable is not an array or object" in WP_Query::get_queried_object()

Reported by: onetarek Owned by: wonderboymusic
Milestone: 3.5 Priority: low
Severity: minor Version: 3.4.2
Component: Query Keywords: has-patch commit
Focuses: Cc:

Description

Today I found following warning message by wordpress/PHP

[22-Sep-2012 11:00:16] PHP Warning:  reset() [<a href='function.reset'>function.reset</a>]: Passed variable is not an array or object in /home/..../public_html/wp-includes/query.php on line 2971


This warning is not occurred for every page visit/query. But it is huge in my error_log.
I opened wp-includes/query.php on line 2971 and found this line

$term = get_term_by( $query['field'], reset( $query['terms'] ), $query['taxonomy'] );


in some case this variable

$query['terms']

is not an object/array.

Now wordpress should check whether this var is an object/array or not before reset() that.


Attachments (1)

check-terms-for-null.diff (493 bytes) - added by wonderboymusic 2 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 @Asif2BD2 years ago

  • Cc asif2bd@… added
  • Keywords needs-patch added

Actually WordPress should handle it, not PHP. Need to change the way function.reset() working.

comment:2 @SergeyBiryukov2 years ago

To reproduce, visit /category/uncategorized/0/.

comment:3 @wonderboymusic2 years ago

  • Keywords has-patch added; needs-testing dev-feedback needs-patch removed
  • Milestone changed from Awaiting Review to 3.5
  • Owner set to wonderboymusic
  • Status changed from new to accepted

Let's not call get_term_by() when there's no terms

comment:4 @scribu2 years ago

  • Keywords commit added
  • Priority changed from normal to low
  • Severity changed from major to minor

comment:5 @scribu2 years ago

  • Summary changed from WordPress Bug - PHP Warning Message "Passed variable is not an array or object" to "Passed variable is not an array or object" in WP_Query::get_queried_object()

comment:6 @nacin2 years ago

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

In 22450:

Don't call get_term_by() in get_queried_object() if we have no terms. props wonderboymusic. fixes #21967.

Note: See TracTickets for help on using tickets.