Created
November 30, 2014 19:56
-
-
Save jayontraps/a2b5e4f2b9266489bdfa to your computer and use it in GitHub Desktop.
Wordpress wp: get custom post type archive listing by year
This file contains 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
// example 'news' cpt | |
function myquery_custom_post_rewrite( $rewrite_rules ) { | |
$pagination_base = $GLOBALS['wp_rewrite']->pagination_base; | |
$myqueryslug = 'news'; | |
$year_archive = array( | |
$myqueryslug . '/([0-9]{4})/' . $pagination_base . '/?([0-9]{1,})/?$' => 'index.php?post_type=' . $myqueryslug . '&year=$matches[1]&paged=$matches[2]', | |
$myqueryslug . '/([0-9]{4})/?$' => 'index.php?post_type=' . $myqueryslug . '&year=$matches[1]', | |
); | |
$rewrite_rules = $year_archive + $rewrite_rules; | |
return $rewrite_rules; | |
} | |
add_filter('rewrite_rules_array', 'myquery_custom_post_rewrite'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment