I have seen many questions/posts regarding this, but have yet to find a decent solution. Basically I am trying to do what wp_get_archives does, but for a custom post type (personally I am unsure why wp_get_archives doesn't support custom post types!).
The code I am currently using is as follows
functions.php
function Cpt_getarchives_where_filter( $where , $r ) {
$post_type = 'events';
return str_replace( "post_type = 'post'" , "post_type = '$post_type'" , $where );
}
sidebar-events.php
add_filter( 'getarchives_where' , 'Cpt_getarchives_where_filter' , 10 , 2 );
wp_get_archives();
remove_filter('getarchives_where' , 'Cpt_getarchives_where_filter' , 10 );
This code displays the dates (e.g. April 2014, March 2014) etc, which is great, but clicking the links just goes to a 404. The URL that is created on each date link is /2014/04/, however it should be something like /events/2014/04/.
Is there any way to include 'events' in the URL so that the archive-events.php template can be used, and is there any reason why the links currently generate a 404?
Many thanks for any help