Make WordPress Core

Opened 9 years ago

Closed 9 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:


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


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 9 years ago.

Download all attachments as: .zip

Change History (7)

#1 @Asif2BD
9 years ago

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

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

#2 @SergeyBiryukov
9 years ago

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

#3 @wonderboymusic
9 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

#4 @scribu
9 years ago

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

#5 @scribu
9 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()

#6 @nacin
9 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.