title: Custom post type yearly/ monthly archive
body: <p>I have a custom post type "news" in my Wordpress site. I am using Advanced Custom Fields plugin to add meta data to each post.</p>
  
  <p>I want to create an array of news items as an archive:</p>
  
  <pre><code>[2013]
      [January] =&gt; 5
  [2012]
      [January] =&gt; 20
      [February] =&gt; 10
  [2011]
      [April] =&gt; 30
  </code></pre>
  
  <p>I managed to get this working using:</p>
  
  <pre><code>    global $wpdb;
      $news = $wpdb-&gt;get_results(
          "SELECT wp_posts.post_date, COUNT(wp_posts.ID) as count
           FROM $wpdb-&gt;posts
           WHERE
           wp_posts.post_type = 'news' AND
           wp_posts.post_status = 'publish' AND
           wp_posts.post_date &lt;= CURDATE() AND
           wp_posts.post_date &gt;= DATE_SUB(CURDATE(), INTERVAL 3 YEAR)
           GROUP BY YEAR(wp_posts.post_date), MONTH(wp_posts.post_date)
           ORDER BY wp_posts.post_date DESC", 
           ARRAY_A);
  
      $archive = array();
      foreach ($news as $post):
          $year = date('Y', strtotime($post['post_date']));      
          $month = date('m', strtotime($post['post_date']));     
          $month_name = date('F', strtotime($post['post_date']));
          $post['url'] = 'NOT SURE ABOUT URL';
          $archive[$year][$month_name] = $post;
      endforeach;
  </code></pre>
  
  <p>I need to be able to link to specific years and months using <code>http://example.com/2012/</code> and <code>http://example.com/2012/10/</code>. </p>
  
  <p>As this involves a custom post type "news" I'm unsure how to make this happen? </p>