Wordpress - Custom Post Type URL Rewriting?
When you register the custom post type, you have to specify that the rewrite rule shouldn't be prepended with the existing URL structure.
In short, this means that this line in your register_post_type
call:
'rewrite' => array('slug' => 'projects'),
should turn into this:
'rewrite' => array('slug' => 'projects','with_front' => false),
For more info, check out the rewrite
argument from the codex entry on register_post_type
edit: just make sure that, after updating the code, you flush the rewrite rules by visiting Settings > Permalinks. Otherwise you'll still see the old links.
I had this problem literally 3 days ago, then I stumbled across a series over at wp.tutsplus.com. I swapped my own code out to accommodate your question better, but this is what I ended up with after following the series. Also, keep in mind that this is untested.
// sets custom post type
function my_custom_post_type() {
register_post_type('Projects', array(
'label' => 'Projects','description' => '',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'post',
'hierarchical' => false,
'publicly_queryable' => true,
'rewrite' => false,
'query_var' => true,
'has_archive' => true,
'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes'),
'taxonomies' => array('category','post_tag'),
// there are a lot more available arguments, but the above is plenty for now
));
}
add_action('init', 'my_custom_post_type');
// rewrites custom post type name
global $wp_rewrite;
$projects_structure = '/projects/%year%/%monthnum%/%day%/%projects%/';
$wp_rewrite->add_rewrite_tag("%projects%", '([^/]+)', "project=");
$wp_rewrite->add_permastruct('projects', $projects_structure, false);
Theoretically, you could swap out whatever you want in the URL stored in the $projects_structure
variable, what is there is just what I ended up using.
Good luck, and as always - make sure to come back and let us know how it worked out! :)