Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function action_generate_rewrite_rules( $wp_rewrite ) {
- $rules = array();
- //Replace POST TYPES HERE in the array below with names of the custom post types that need date-based archives.
- foreach( array( POST TYPES HERE ) as $post_type ) {
- $post_type_object = get_post_type_object( $post_type );
- $post_type_slug = '';
- if( $post_type_object->rewrite[ 'with_front' ] && $wp_rewrite->front != '/' )
- $post_type_slug .= $wp_rewrite->front;
- $post_type_slug .= $post_type_object->rewrite[ 'slug' ];
- $post_type_slug = path_join( $post_type_slug, 'date' );
- $rules = array_merge( $rules, array(
- $post_type_slug . '/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=' . $post_type . '&year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]',
- $post_type_slug . '/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=' . $post_type . '&year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]',
- $post_type_slug . '/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$' => 'index.php?post_type=' . $post_type . '&year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]',
- $post_type_slug . '/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$' => 'index.php?post_type=' . $post_type . '&year=$matches[1]&monthnum=$matches[2]&day=$matches[3]',
- $post_type_slug . '/([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=' . $post_type . '&year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]',
- $post_type_slug . '/([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=' . $post_type . '&year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]',
- $post_type_slug . '/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$' => 'index.php?post_type=' . $post_type . '&year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]',
- $post_type_slug . '/([0-9]{4})/([0-9]{1,2})/?$' => 'index.php?post_type=' . $post_type . '&year=$matches[1]&monthnum=$matches[2]',
- $post_type_slug . '/([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=' . $post_type . '&year=$matches[1]&feed=$matches[2]',
- $post_type_slug . '/([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?post_type=' . $post_type . '&year=$matches[1]&feed=$matches[2]',
- $post_type_slug . '/([0-9]{4})/page/?([0-9]{1,})/?$' => 'index.php?post_type=' . $post_type . '&year=$matches[1]&paged=$matches[2]',
- $post_type_slug . '/([0-9]{4})/?$' => 'index.php?post_type=' . $post_type . '&year=$matches[1]'
- ) );
- }
- $wp_rewrite->rules = $rules + $wp_rewrite->rules;
- }
Advertisement
Add Comment
Please, Sign In to add comment