Use date in the URL of custom post type

So I’ve created a custom post type, say reviews, and its archive is available at <domain>/reviews/. I want to categorize them by date. So every day (or week) I publish a reviews type post and I want its url to be <domain>/reviews/2013/09/05/<post-name>, so that users will be able to list all the reviews from specific year, month or day. Just like we have a similar feature for the regular posts. All the plugins I’ve tried are old and aren’t working with WP 3.6. So is there any solution (maybe even built-in)? Or at least some direction so I can code it myself? I would appreciate any help.

Related posts

1 comment

  1. Custom post types can not use the “day/name” permalink structure defined in WordPress permalinks settings. You need to add your own rewrite rules to fit your needs.

    For example:

    add_action('init','my_rewrite_rules');
    function my_rewrite_rules(){
        // Replace custom_post_type_slug with the slug of your custom post type
        add_rewrite_rule( 'custom_post_type_slug/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(.+)/?$', 'index.php?custom_post_type_slug='.$matches[4], 'top' );
    }
    

    Note that I’ve not tested the code above. You need to flush the rewrite rules before you test it.

Comments are closed.