I have created a CPT (Custom Post Type) in Wordpress called "minutes" and am using the following php to give the post an archive
add_filter( 'getarchives_where', 'getarchives_where_filter', 10, 2 );
add_filter( 'generate_rewrite_rules', 'generate_events_rewrite_rules' );
function getarchives_where_filter( $where, $args ) {
if ( isset($args['post_type']) ) {
$where = "WHERE post_type = '$args[post_type]' AND post_status = 'publish'";
}
return $where;
}
function generate_minutes_rewrite_rules( $wp_rewrite ) {
$event_rules = array(
'minutes/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$' => 'index.php?post_type=minutes&year=$matches[1]&monthnum=$matches[2]&day=$matches[3]',
'minutes/([0-9]{4})/([0-9]{1,2})/?$' => 'index.php?post_type=minutes&year=$matches[1]&monthnum=$matches[2]',
'minutes/([0-9]{4})/?$' => 'index.php?post_type=minutes&year=$matches[1]'
);
$wp_rewrite->rules = $minutes_rules + $wp_rewrite->rules;
}
function get_archives_minutes_link( $link ) {
return str_replace( get_site_url(), get_site_url() . '/minutes', $link );
};
and to create a monthly side bar on my single post template. I am using this:
add_filter( 'get_archives_link', 'get_archives_minutes_link', 10, 2 );
wp_get_archives( array( 'post_type' => 'minutes' ) );
wp_get_archives( array( 'post_type' => 'minutes', 'type' => 'yearly' ) );
wp_get_archives( array( 'post_type' => 'minutes', 'type' => 'monthly' ) );
wp_get_archives( array( 'post_type' => 'minutes', 'type' => 'daily' ) );
remove_filter( 'get_archives_link', 'get_archives_minutes_link', 10, 2 );
I have resaved the permalinks but the monthly links dont link to the archive.
any ideas?
https://developer.wordpress.org/themes/basics/template-hierarchy/#custom-post-types
Make sure 'has_archive' => true
Then, create an archive-minutes.php file. This will be the archive for the minutes page.
In that page, use the default wordpress loop, or whatever you want to get the content