Warning: Invalid argument supplied for foreach() wp-includes/query.php on line 2762

This was an annoying bug on one of my wordpress + buddypress for a while and the fix is amazingly simple :

Edit your wp-includes/query.php around line 2762

// Always sanitize
foreach ( $this->posts as $i => $post ) {
    $this->posts[$i] = sanitize_post( $post, 'raw' );
}

and replace by :

// Always sanitize
if ( $this->post_count > 0 ) {
    foreach ( $this->posts as $i => $post ) {
        $this->posts[$i] = sanitize_post( $post, 'raw' );
    }
}

Fab

Computer Engineer - Web juggler

If you like this post, you should follow me on Twitter

One Thought on “Warning: Invalid argument supplied for foreach() wp-includes/query.php on line 2762

  1. That was amazing thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *


× four = 8

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Post Navigation