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: jrcowher 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)

Screen shot 2011-01-20 at 3.01.43 PM.png (171.0 KB) - added by jrcowher 2 years ago.
Screen shot 2011-01-20 at 3.06.06 PM.png (25.3 KB) - added by jrcowher 2 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 follow-up: ↓ 2   nacin2 years ago

Were rewrite rules flushed at any point?

comment:2 in reply to: ↑ 1   jrcowher2 years ago

Replying to nacin:

Were rewrite rules flushed at any point?

Yes, quite a few times via Settings -> Permalinks -> Save Changes

comment:3 follow-up: ↓ 4   scribu2 years ago

Please paste the full code you're using to register the post type.

comment:4 in reply to: ↑ 3   jrcowher2 years ago

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');

Note: See TracTickets for help on using tickets.