Wordpress WP_Query() Not working properly
<p>I would like to know why we get an error when we implement this code in our <code>sidebar.php</code>:</p>

<pre><code>$categories = get_categories(); 
foreach($categories as $category) 
{ 
  printf('&lt;h2&gt;%s&lt;/h2&gt;&lt;ul&gt;', $category-&gt;cat_name);
  $posts = new WP_Query('cat='.$category-&gt;cat_ID);
  while($posts-&gt;have_posts())
  {     
    $posts-&gt;the_post();
    echo '&lt;li&gt;', the_title(), '&lt;/li&gt;'; 
  }   
  print '&lt;/ul&gt;';  
}
</code></pre>

<p>The error we are getting is:</p>

<blockquote>
  <p>Fatal error: Cannot use object of type WP_Query as array in C:\xampp\htdocs\wordpress\wp-includes\query.php on line 2374</p>
</blockquote>
