title: Wordpress - Count posts for each year
body: <p>I'm using the following code to list all years from my blog, I guess we can call it an archive.</p>
  
  <pre><code>&lt;?php
  $years = $wpdb-&gt;get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb-&gt;posts ORDER BY post_date DESC");
  foreach($years as $year) : ?&gt;
      &lt;?php echo $year ?&gt;
  &lt;?php endforeach; ?&gt;
  </code></pre>
  
  <p>What I'd like to achieve though is to also display, in front of each year, the number of posts (count) that each year has. Example:</p>
  
  <pre><code>2015 (5 posts)
  2014 (3 posts)
  2011 (10 posts)
  </code></pre>
  
  <p>I found a hint somewhere and tried to implement it, but didn't work. Here's what I was trying:</p>
  
  <pre><code>&lt;?php
  $years = $wpdb-&gt;get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb-&gt;posts ORDER BY post_date DESC");
  $count = $years-&gt;post_count;
  foreach($years as $year) : ?&gt;
      &lt;?php echo $year ?&gt; (&lt;?php echo $count ?&gt; posts)
  &lt;?php endforeach; ?&gt;
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Thank you.</p>