Been looking for someone with this same problem for hours now so I decided to post my own thread.
I have a hierachical custom post type called contact-information. Using this I have parentpages which contain no information, and childpages which does! In the single-contact-information.php I’ve set a redirect rule that redirects a parent to its first child. This works like a charm!
However! Just a few days ago the childpages suddenly started going 404 on me! It seems the pages do exist, and they are indeed set as children of the parents, but the permalinks doesnt work. Here’s my permalink-structure, the basic one:
/%year%/%monthnum%/%day%/%postname%/
So basically:
mysite.com/contact-information/parentpage/childpage
DOESNT work, but
mysite.com/contact-information/childpage
DOES WORK, aswell as
mysite.com/contact-information/parentpage
Here’s the code for creating the custom post type, it’s from the Custom post types UI plugin:
register_post_type('contact-information', array( 'label' => 'Contact info','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post','hierarchical' => true,'rewrite' => array('slug' => ''),'query_var' => true,'supports' => array('title','revisions','page-attributes',),'labels' => array (
'name' => 'Contact info',
'singular_name' => 'Contact information',
'menu_name' => 'Contact info',
'add_new' => 'Add Contact information',
'add_new_item' => 'Add New Contact information',
'edit' => 'Edit',
'edit_item' => 'Edit Contact information',
'new_item' => 'New Contact information',
'view' => 'View Contact information',
'view_item' => 'View Contact information',
'search_items' => 'Search Contact info',
'not_found' => 'No Contact info Found',
'not_found_in_trash' => 'No Contact info Found in Trash',
'parent' => 'Parent Contact information',
),) );
EDIT:
I just tried creating a CPT by myself aswell in functions using http://themergency.com/generators/wordpress-custom-post-types/
and the issue remains so I’m pretty sure it’s got to do with the permalinks, I just have no idea what!
I battled to create hierarchical for post types and custom taxonomies and then found this great code, maybe you can use it to make a date based sctructure: https://wordpress.stackexchange.com/a/55366/17048
Try this plugin http://wordpress.org/extend/plugins/custom-post-type-permalinks/.
I had a lot of problems with permalinks for custom type, and 404-errors, until I started to use this plugin.
In looking at your code, you may want to look at your rewrite array key.
This would rewrite your custom post type url.
One gotcha though…when you add this to your function, you’ll want to go to your permalink structure and just hit save again. You don’t have to change anything, but by hitting save, it rewrites your .htaccess file so that WordPress recognizes the new slug.
If you were dev’ing this for commercial or public release, you could always do:
Here is the reference link: http://codex.wordpress.org/Function_Reference/flush_rewrite_rules
And the link for custom post types. A little over half way down the page is the setup for the rewrite slug:
http://codex.wordpress.org/Function_Reference/register_post_type
I just prefer to be a bit more hands-on with my WordPress installations, so I know exactly what is going on.