Opened 2 years ago
Last modified 2 years ago
#16323 new defect (bug)
Hierarchical Custom Post Type Bug - invalid name query var generated
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Permalinks | Version: | 3.0.4 |
| Severity: | normal | Keywords: | |
| Cc: |
Description
When starting off with the post type set to non-hierarchical and then setting the hierarchical parameter in register_post_type() to true Wordpress will generate an invalid name query var (see attached files). If a generate a new rewrite rule in my functions file (e.g. service/(.*?)/(.*?)/?$' => 'index.php?post_type=service&name=$matches[2]) this appears to fix the problem. Removing the custom rewrite rule will cause the error to reappear.
Attachments (2)
Change History (6)
Replying to nacin:
Were rewrite rules flushed at any point?
Yes, quite a few times via Settings -> Permalinks -> Save Changes
Please paste the full code you're using to register the post type.
Replying to scribu:
Please paste the full code you're using to register the post type.
function post_type_service() {
register_post_type(
'service', array(
'labels' => array(
'name' => 'Services',
'singular_name' => 'Service',
'add_new' => 'Add new',
'add_new_item' => 'Add new service',
'edit_item' => 'Edit service',
'search_items' => 'Search services',
'not_found' => 'No services found',
'not_found_in_trash' => 'No services found in trash',
),
'menu_position' => 20,
'public' => true,
'show_ui' => true,
'hierarchical' => true,
'query_var' => false,
'exclude_from_search' => false,
'supports' => array(
'title',
'editor',
'page-attributes'
)
));
register_taxonomy(
'service-cats', 'service', array(
'hierarchical' => true, // Category or Tag functionality
'labels' => array(
'name' => 'Categories',
'singular_name' => 'Category',
'search_items' => 'Search categories',
'popular_items' => 'Popular categories',
'all_items' => 'All categories',
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => 'Edit category',
'update_item' => 'Update category',
'add_new_item' => 'Add new category',
'new_item_name' => 'New category',
'separate_items_with_commas' => 'Separate categories with commas',
'add_or_remove_items' => 'Add or remove categories',
'choose_from_most_used' => 'Choose from most used categories'
)
)
);
}
add_action('init', 'post_type_service');

Were rewrite rules flushed at any point?