Skip to content

Instantly share code, notes, and snippets.

@NatalieMac
Created October 3, 2014 04:19
Show Gist options
  • Save NatalieMac/92e1f7bc77d6957f587c to your computer and use it in GitHub Desktop.
Save NatalieMac/92e1f7bc77d6957f587c to your computer and use it in GitHub Desktop.
<?php
// add yearly archives for custom post type
function custom_post_rewrite( $rewrite_rules ) {
$pagination_base = $GLOBALS['wp_rewrite']->pagination_base;
$slug = 'cpt slug goes here';
$year_archive = array(
$slug . '/([0-9]{4})/' . $pagination_base . '/?([0-9]{1,})/?$' => 'index.php?post_type=' . $slug . '&year=$matches[1]&paged=$matches[2]',
$slug . '/([0-9]{4})/?$' => 'index.php?post_type=' . $slug . '&year=$matches[1]',
);
$rewrite_rules = $year_archive + $rewrite_rules;
return $rewrite_rules;
}
add_filter('rewrite_rules_array', 'custom_post_rewrite');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment