#13560 closed defect (bug) (fixed)
Add custom taxonomy to Pages admin menu
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.0.1 | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Taxonomy | Keywords: | custom taxonomy, page, edit-tags.php |
Focuses: | Cc: |
Description
When adding a custom taxonomy to posts, a submenu is added beneath 'Posts' to allow editing of the taxonomy. However, a menu is not added if the taxonomy is attached to Pages, even though the taxonomy works fine when creating/editing posts.
Adding the following code to wp-admin/menu.php fixes this.
immediately after
$submenu['edit.php?post_type=page'][10] = array( _x('Add New', 'page'), 'edit_pages', 'post-new.php?post_type=page' );
(line 110 in 3.0b2)
add
$i = 15; foreach ( $wp_taxonomies as $tax ) { if ( ! $tax->show_ui || ! in_array('page', (array) $tax->object_type, true) ) continue; $submenu['edit.php?post_type=page'][$i++] = array( esc_attr($tax->label), $tax->manage_cap, 'edit-tags.php?taxonomy=' . $tax->name ); } unset($tax);
(basically a duplicate of the code earlier in menu.php which adds the edit taxonomy submenu for pages).
Change History (6)
#3
@
15 years ago
- Keywords custom taxonomy page edit-tags.php added
- Resolution fixed deleted
- Status changed from closed to reopened
This fix, is missing the post_type=page parameter when building the edit-tags.php URL. The result is that the edit-tags.php page by default thinks it's editing a Post, so it closes tha Pages menu and opens the Posts menu, and the links to view the Pages assigned to a Taxonomy don't work (since they default to Posts too).
This line:
$submenu['edit.php?post_type=page'][$i++] = array( esc_attr( $tax->labels->name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name );
Should be changed to:
$submenu['edit.php?post_type=page'][$i++] = array( esc_attr( $tax->labels->name ), $tax->cap->manage_terms, 'edit-tags.php?post_type=page&taxonomy=' . $tax->name );
As a workaround, you can add a custom hook:
function modify_submenu() { global $submenu; foreach($submenu['edit.php?post_type=page'] as $key=>$smenu) { $submenu['edit.php?post_type=page'][$key][2] = $smenu[2].'&post_type=page'; } } add_action('admin_head', 'modify_submenu');
#4
@
15 years ago
- Milestone changed from 3.0 to 3.0.1
- Owner set to nacin
- Status changed from reopened to accepted
(In [14953]) Show taxonomies registered against the page type in the Pages submenus. Props markauk. fixes #13560