Created
October 3, 2014 04:19
-
-
Save NatalieMac/92e1f7bc77d6957f587c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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