Again with the custom post type extensions. This function lets the native WordPress `wp_get_archives()` [^1] [^2] know about public custom post types; just add it to the `functions.php` of your theme. Of note: the builtin `link` post type can be included at the `array_merge()` point; I just had no use for it.
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 );
}
## References
[^1]: [Function Reference/wp get archives](http://codex.wordpress.org/Template_Tags/wp_get_archives)
[^2]: [Custom post type permalinks](http://shibashake.com/wordpress-theme/custom-post-type-permalinks-part-2#comment-1765)
This is super!
Thanks 🙂
Also having this issue.. the wp_get_archives function (set to yearly type) brings up domain.com/2011 which includes all post types… I need to be able to have it so if the archive is accessed via the custom post type section, it only brings up those, and not everything…
any thoughts/help would be greatly appreciated!! been looking everywhere.
Perfect…. Super thought 😉
Worked like a charm, Im using December 2013 wordpress 3.7. Slim and plain solution to get custom post types in default archive mecanism and template.
Could someone give an example of how you would query with this added variable
This is just what I was after, thanks!
I am using this in a select drop down with wp_get_archives – can I specify which custom post type to use? As I have several but only want to show one type.