How do you display the archives of a Custom Post Type by Year & Month?
Yes, you can.
All you need is make a filter for
then call this:
Whenever you want to display archive by custom post type, just pass the post_type args:
You don't, the official line from the Wordpress developers was that custom post types weren't intended to do the job of normal ordinary posts, and that if you need post archives of dates etc, then you're not doing things correctly, and you're better off using post formats etc..
Custom post types are intended for web applications etc, whereas doing something such as setting up a custom post type that acts as a secondary or parallel blog with a different name, e.g. blog vs news, with the same abilities, is not what the feature was intended for, and would mean other technical issues arising from its implementation.
If you are still insistent on this, and simply using custom taxonomies and post formats is not enough, you could add rewrite rules in functions.php and redirect year/month archives in certain URLs to the post archive page, and then check on the custom post archive page if you've specified variables in your rewrite rules and load a different template, making sure in your rewrite rules to set the appropriate values.
If you want to avoid messing around with code and want more options for your archives then use Custom Post Type Archives plugin - http://wordpress.org/extend/plugins/custom-post-type-archives/.
This plugin creates a function called
Only problem it is seems to not work with pretty permalinks, so you need to modify the plugin with this fix reference listed here.
Replace this code in the plugin file "post-type-archives.php" (should be starting at line 164):
With this code below: