﻿id,summary,reporter,owner,description,type,status,priority,milestone,component,version,severity,resolution,keywords,cc
22061,"If $this->posts is empty, don't do stuff to it",wonderboymusic,wonderboymusic,"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",defect (bug),closed,normal,3.5,Query,2.9,normal,fixed,has-patch,
