[wp-trac] [WordPress Trac] #22061: If $this->posts is empty, don't do stuff to it
WordPress Trac
wp-trac at lists.automattic.com
Sun Sep 30 19:30:40 UTC 2012
#22061: If $this->posts is empty, don't do stuff to it
----------------------------+--------------------------
Reporter: wonderboymusic | Type: defect (bug)
Status: new | Priority: normal
Milestone: 3.5 | Component: Query
Version: | Severity: normal
Keywords: has-patch |
----------------------------+--------------------------
I started noticing close to 1000 of these a day in our logs: {{{Error:
Invalid argument supplied for foreach()}}}. Googlebot is the culprit for
the requests, but the error is firing because {{{$this->posts}}} in
{{{WP_Query::get_posts()}}} can be an empty array, but that won't stop us
from iterating over it.
{{{
$this->post_count = count( $this->posts );
// Always sanitize
foreach ( $this->posts as $i => $post ) {
$this->posts[$i] = sanitize_post( $post, 'raw' );
}
if ( $q['cache_results'] )
update_post_caches($this->posts, $post_type,
$q['update_post_term_cache'], $q['update_post_meta_cache']);
if ( $this->post_count > 0 ) {
$this->post = $this->posts[0];
}
}}}
My patch tucks the {{{foreach}}} and {{{update_post_caches}}} into the
final IF statement
--
Ticket URL: <http://core.trac.wordpress.org/ticket/22061>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list