Custom Post Type Archives by Year & Month?

Yes, you can.
All you need is make a filter for wp_get_archives(); so it accepts post_type parameter:

function my_custom_post_type_archive_where($where,$args){  
    $post_type  = isset($args['post_type'])  ? $args['post_type']  : 'post';  
    $where = "WHERE post_type="$post_type" AND post_status="publish"";
    return $where;  
}

then call this:

add_filter( 'getarchives_where','my_custom_post_type_archive_where',10,2);

Whenever you want to display archive by custom post type, just pass the post_type args:

$args = array(
    'post_type'    => 'your_custom_post_type',
    'type'         => 'monthly',
    'echo'         => 0
);
echo '<ul>'.wp_get_archives($args).'</ul>';

Leave a Comment