Title: [Plugin: Custom Post Permalinks] Yearly archives
Last modified: August 19, 2016

---

# [Plugin: Custom Post Permalinks] Yearly archives

 *  [beetrootman](https://wordpress.org/support/users/beetrootman/)
 * (@beetrootman)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/plugin-custom-post-permalinks-yearly-archives/)
 * Ok, this plugin works great and sets up my permalinks so I can access yearly 
   archives like so:
 * [http://mysite/custom-type/2010](http://mysite/custom-type/2010)
 * But do you have any idea how I can actually generate a list in a template that
   will link to the yearly archives. wp_get_archives has no option for custom post
   types.
 * [http://wordpress.org/extend/plugins/custom-post-permalinks/](http://wordpress.org/extend/plugins/custom-post-permalinks/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [J B](https://wordpress.org/support/users/johnpbloch/)
 * (@johnpbloch)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/plugin-custom-post-permalinks-yearly-archives/#post-1693075)
 * I did this once and you basically have to rewrite the wp_get_archives function
   to suit your needs.
 *  [Fahad Murtaza](https://wordpress.org/support/users/fahdi/)
 * (@fahdi)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/plugin-custom-post-permalinks-yearly-archives/#post-1693160)
 * [@beetrootman](https://wordpress.org/support/users/beetrootman/):
 * This code should work for you. Use before calling **wp_get_archives **on the 
   template page. This will generate your archive links with the replacement of 
   post type ‘post’ with your custom post type.
 *     ```
       add_filter( 'getarchives_where' , 'fm_getarchives_where_filter' , 10 , 2 ); 
   
       function fm_getarchives_where_filter( $where , $r ) {
       	$args = array( 'public' => true , '_builtin' => false );
       	$output = 'names'; $operator = 'and';
       	$post_types = get_post_types( $args , $output , $operator );
       	$post_types = array_merge( $post_types , array( 'post' ) );
       	$post_types = "'" . implode( "' , '" , $post_types ) . "'";
       	return str_replace( "post_type = 'post'" , "post_type = 'your_custom_post_type_name'" , $where );
       }
       ```
   
 * Just replace **your_custom_post_type_name **above with your custom post type 
   name and you are all set.
 * Regards,
    Fahd Murtaza
 *  [Fahad Murtaza](https://wordpress.org/support/users/fahdi/)
 * (@fahdi)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/plugin-custom-post-permalinks-yearly-archives/#post-1693161)
 * I wont recommend putting it in functions.php as functions.php is for all the 
   wordpress theme files while this filter is to be used on specific template. For
   a generic archive, if you want to add the custom post types to the results produced
   by **wp_get_archives **, then you might have to consider using this code in your
   functions.php
 *     ```
       add_filter( 'getarchives_where' , 'ucc_getarchives_where_filter' , 10 , 2 ); 
   
       function ucc_getarchives_where_filter( $where , $r ) {
       	$args = array( 'public' => true , '_builtin' => false );
       	$output = 'names'; $operator = 'and';
       	$post_types = get_post_types( $args , $output , $operator );
       	$post_types = array_merge( $post_types , array( 'post' ) );
       	$post_types = "'" . implode( "' , '" , $post_types ) . "'";
       	return str_replace( "post_type = 'post'" , "post_type IN ( $post_types )" , $where ); }
       ```
   
 * Source:
    [http://bajada.net/2010/07/15/adding-custom-post-types-to-wp_get_archives](http://bajada.net/2010/07/15/adding-custom-post-types-to-wp_get_archives)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘[Plugin: Custom Post Permalinks] Yearly archives’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/custom-post-permalinks.svg)
 * [Custom Post Permalinks](https://wordpress.org/plugins/custom-post-permalinks/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/custom-post-permalinks/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/custom-post-permalinks/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-post-permalinks/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-post-permalinks/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-post-permalinks/reviews/)

 * 3 replies
 * 3 participants
 * Last reply from: [Fahad Murtaza](https://wordpress.org/support/users/fahdi/)
 * Last activity: [14 years, 8 months ago](https://wordpress.org/support/topic/plugin-custom-post-permalinks-yearly-archives/#post-1693161)
 * Status: not resolved