Using dates in custom post_type Permalink in Wordpress 3.0

I am adding a custom post_type to Wordpress and want the permalink structure to look like this:

/%post_type%/%year%/%monthnum%/%postname%/ 

I cannot figure out how to add date tags. Using this code, give me /my_type/example-post-slug/ :

 register_post_type( 'customtype', array( ...other options... 'rewrite' => array('slug' => 'my_type'), )); 

How to include dates?

+6
date wordpress permalinks custom-post-type
source share
3 answers

You can achieve this with the Custom Permanent Publishing Options plugin. Just install the plugin and change the permalink format in the settings.

+1
source share

I found a partial solution that allows you to recognize and save a permalink when loading a page in the address bar, but not update on the editing screen or other links to a message on the site. Add the following functions to the functions.php file or plugin with a specific site, replacing example-post-type with the identifier of your message type.

 function example_rewrite() { add_rewrite_rule('^example-post-type/([0-9]{4})/([0-9]{1,2})/([^/]*)/?','index.php?post_type=example-post-type&year=$matches[1]&monthnum=$matches[2]&name=$matches[3]','top'); } add_action('init', 'example_rewrite'); 

This uses the Rewrite API registered here. For more tips on understanding the process, see here .

One thing to keep in mind, no matter how you do it, it is impossible for two posts to have the same slime, even if they have different dates. This is because if the permalink always changes, they may collide and cause errors.

0
source share

Use this to make it work 100%:

 'rewrite' => array('slug'=>date('Y').'/'.date('m').'/custom_post_type_slug','with_front'=>true) 
-2
source share

All Articles