Get monthly archives for custom post type

You can use getarchives_where hook of wp_get_archives() function

Add this function to your functions.php:

function Cpt_getarchives_where_filter( $where , $r ) {

  $post_type="blog";
  return str_replace( "post_type="post"" , "post_type="$post_type"" , $where );
}

Then when you want your monthly archive put this:

add_filter( 'getarchives_where' , 'Cpt_getarchives_where_filter' , 10 , 2 );
wp_get_archives();
remove_filter('getarchives_where' , 'Cpt_getarchives_where_filter' , 10 );

Leave a Comment