1

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.

1 Answer 1

0

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.

5
  • Thanks for the help, however this rewrite rule redirects to the index page for some reason + as I understand, there's no option for archive for custom post types (just like we have for regular posts <domain>/2013/09 etc.), which is the important part here. Am I right?
    – somebody
    Sep 6, 2013 at 10:41
  • Are you really redirected to index page? I've tried a similar rewrite rule and I'm no redirected, I get the home page of my site but there is no redirection, so I think the rewrite rules are not the corrects but I still think that this can be done adding the correct rewrite rules.
    – cybmeta
    Sep 6, 2013 at 11:01
  • Yes, instead of the article itself, I get an index page (which is a progress in some sense, because previously I simply got 404).
    – somebody
    Sep 6, 2013 at 11:09
  • I have no time today to investigate this. You can check this plugin and see how it does the job.
    – cybmeta
    Sep 6, 2013 at 11:18
  • Thank you so much! It works fine now. How could have I missed this plugin!
    – somebody
    Sep 6, 2013 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.