WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any way to specify a time period for wp_dropdown_categories or wp_list_categories or something else...? I want to create a archive page, so that if your in the archive of 2010, you'll see only the categories wich were used in 2010.

do i have to write a custom function for this one? if yes, any suggestion where start?

tnx for any kind of answer!

best regards,


share|improve this question

I have a fancy function that i made just for that:

/* Create taxomony term list of posts based on given year 
* @param $year - (int) 4 digits - the year to return the list of. required
* @param $taxonomy - (string) the taxonomy name of which the retreve the terms. required
* @param $echo_out - (boolean) true - to echo false to return default false.
* @param $type - (array) of args that tels the function what to get.
* examples: 
select dropdownlist:
'type' => 'select', //(string)
'name' => 'cat', //(string) name of the select dropdown.
'js' => ture // (boolean) wheter or not to pring out onchange javascript redirect function.

'type' => 'list', //(string)
'before_list' => '<ul>', //(string) html tag (<ul>,<div> you can add classes here).
'after_list' => '</ul>', //(string) html tag (</ul>,</div>)
'before_link' => '<li>', //(string) html tag (<li>,<div>,<span> you can add classes here).
'after_link' => '</li>' //(string) html tag (</li>,</div>,</span>,<br/>).

return array:
'type' => 'return-list', //(string)
'return' => 'ID' // (string) what to return (accepts ID or name).

function yearly_taxonomy_list($year,$type, $taxonomy,$echo_out = false){

    $args = array(
        'year' => $year,
        'posts_per_page' => -1
    $the_query = new WP_Query( $args );
    $cats = array();
    while ($the_query->have_posts()){
        $curent_cats = wp_get_object_terms( $post->ID, $taxonomy);
        foreach ($curent_cats as $c){
            if (!in_array($c,$cats)){
                $cats[] = $c;
    if (isset($type['type']) && $type['type'] =='select'){
        $out = '<select name="'.$type['name'].'" id="'.$type['name'].'" >';
        foreach ($cats as $cd){
            $out .= '<option value='.get_term_link( $cd->term_id, $taxonomy ).'">'.$cd->name.'</option>';
        $out .= '</select>';

            $js = '<script type="text/javascript">
            var dropdown = document.getElementById("'.$name.'");
            function onCatChange() {
                if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
                    location.href = dropdown.options[dropdown.selectedIndex].value;
            dropdown.onchange = onCatChange;
            $out .=  $js;
    }elseif (isset($type['type']) && $type['type'] =='list'){
        $out = $type['before_list'];
        foreach ($cats as $cd){
            $out .= $type['before_link'].'<a href="'.get_term_link( $cd->term_id, $taxonomy ).'">'.$cd->name.'</a>'.$type['after_link'];
        $out .= $type['after_list'];
    //return array
    elseif (isset($type['type']) && $type['type'] =='return-list'){
        //array of  IDS
        if ($type['return'] =='ID'){
            foreach ($cats as $cd){
                $out[] = $cd->term_id;
        //array of  names
        if ($type['return'] =='name'){
            foreach ($cats as $cd){
                $out[] = $cd->name;
        return $out;
        $out = 'something went worng';
        echo $out;
        return $out;


// category dropdown with JavaScript OnChange redirect
$type=array('type' => 'select', 'name' => 'cat','js' => ture );
yearly_taxonomy_list(2010,$type, 'category' ,true);

//unordered list of categories
'type' => 'list', 
'before_list' => '<ul class="yearly-cats">', 
'after_list' => '</ul>', 
'before_link' => '<li>',
'after_link' => '</li>');
yearly_taxonomy_list(2010,$type, 'category' ,true);

//return array ids of categories 
$type=array('type' => 'return-list', 'return' => 'ID');
$cat_ids = yearly_taxonomy_list(2010,$type, 'category' ,true);
share|improve this answer
Great! Tnx Bainternet! I kinda made my own function already, but i will definitely give yours a try, cos it's looks better that mine, mine is kinda query heavy :) – CRIS Apr 7 '11 at 0:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.