title: Wordpress yearly archives for current category
body: <p>This has really been driving me mad for a while now, so I'm hoping someone can help. I'm trying to use <code>wp_get_archives()</code> to display a list of links to yearly archives <em>that show posts within the current category</em>.</p>
  
  <p>Importantly, I'm trying to do this <strong>without</strong> a plugin and just use the functions file or even a <code>WP_Query</code> loop.</p>
  
  <p><strong>Example</strong></p>
  
  <p>Imagine I have the following categories all filled with posts:</p>
  
  <p>Exhibitions (parent)<br>
  --Current (child)<br>
  --Past (child)</p>
  
  <p>Artworks (parent)<br>
  --Recent (child)<br>
  --Featured (child)<br>
  --Old (child)</p>
  
  <p>What I'm trying to do is essentially this:</p>
  
  <pre><code>/* Get current Cat ID */
  function getCurrentCatID() {
      global $wp_query;
      if(is_category() || is_single()){
          $cat_ID = get_query_var('cat');
      }
      return $cat_ID;
  }
  
  $currentCat = getCurrentCatID();
  
  wp_get_archives('type=yearly&amp;cat=$currentCat'); // But, you can't filter this by category it seems
  </code></pre>
  
  <p>So, if I view the 'Exhibitions' category (which uses category.php), <code>wp_get_archives()</code> would show links for 2012, 2011, 2010 etc.</p>
  
  <p>When I click 2011, I would see posts that are in the category 'Exhibitions' AND it's child categories (also important).</p>
  
  <p>I've found this post which might hold the answer: <a href="https://stackoverflow.com/questions/2789228/exclude-category-from-wp-get-archives">Exclude Category From wp_get_archives?</a></p>
  
  <p>But I don't know how I would use the current category being viewed within filters mentioned in the post nor how I would add multiple categories to it (i.e. the parent category plus it's children).</p>
  
  <p>Any help massively appreciated.</p>
  
  <p>Osu</p>