I'm adding a custom post_type to Wordpress, and would like the permalink structure to look like this:
/%post_type%/%year%/%monthnum%/%postname%/
I can't figure out how to add the date tags. Using this code, gives me /my_type/example-post-slug/
:
register_post_type( 'customtype', array(
...other options...
'rewrite' => array('slug' => 'my_type'),
));
How do I include the dates?
You can achieve this with the plugin Custom Post Type Permalinks. Just install the plugin and change the permalink format in the settings.
Use this it's working 100% :
I have found a partial solution which allows for the permalink to be recognized and preserved upon loading the page in the address bar, but not updated in the edit screen or other links to the post on the site. Add the following to functions.php or a site specific plugin, replacing example-post-type with the identifier of your post type.
This uses the Rewrite API documented here To find more tips on understanding the process see here.
One thing to bear in mind is no matter how you do this, it is impossible for two posts to have the same slug, even if they have different dates. This is because if the permalink scheme is ever changed, they could clash and cause errors.