我知道我正在发布necro帖子,但我最近也遇到了同样的问题。请注意我用的是Rao的solution on SO 找到这个答案。
假设您的CPT被称为“注释”。
/**
* @see https://codex.wordpress.org/Plugin_API/Filter_Reference/menu_order
*/
add_filter( \'custom_menu_order\', \'change_note_submenu_order\' );
/**
* Change the submenu order for the Note CPT in the Admin panel
*
* @param [type] $menu_ord I don\'t think this is actually used for anything...
* @return [type] $menu_ord
* @see https://stackoverflow.com/questions/18766477/wordpress-change-admin-submenu-order
*/
function change_note_submenu_order( $menu_ord ) {
global $submenu;
/* Uncomment the line below to see all menu orders */
// echo \'<pre>\'.print_r($submenu,true).\'</pre>\';
/**
* NOTE: Original note submenu order should be:
* 5 (note list),
* 10 (Add new),
* 15 (Categories),
* 16 (Tags),
* 17 (Your Custom Page added via add_submenu_page) */
$arr = array();
$arr[] = $submenu[\'edit.php?post_type=note\'][17]; // Custom menu page (Omit if unused)
$arr[] = $submenu[\'edit.php?post_type=note\'][5]; // Note List
$arr[] = $submenu[\'edit.php?post_type=note\'][10]; // Add New Note
$arr[] = $submenu[\'edit.php?post_type=note\'][15]; // Categories
$arr[] = $submenu[\'edit.php?post_type=note\'][16]; // Tags
$submenu[\'edit.php?post_type=note\'] = $arr;
return $menu_ord;
}
绝对要注释掉
echo \'<pre>\'.print_r($submenu,true).\'</pre>\';
如果你有麻烦。还请记住,您也可以在
change_note_submenu_order
作用
$notes_list = array("Notes", "edit_posts", "edit.php?post_type=notes");
$custom_page = array("Custom Menu Page Title", "Capability", "Menu Slug", "Page Title");
$new_note = array("Add New", "edit_posts", "post-new.php?post_type=note");
$arr = array($custom_page, $notes_list, $new_note);
$submenu[\'edit.php?post_type=note\'] = $arr;
希望这对别人有帮助!