I have created 3 post types with Toolset: Brags, Dogs, and Members.
I have also created a top-level menu using the following code:
//Create Admin menu for CRFCRC Custom Post Types
add_action( 'admin_menu', 'crfcrc_admin_menu' );
function crfcrc_admin_menu() {
$iconURL = 'dashicons-awards';
add_menu_page( 'CRFCRC Admin Menu', 'CRFCRC', 'manage_options', 'crfcrc-data', 'crfcrc_data_admin_page', $iconURL, 3 );
add_submenu_page('crfcrc-data', 'CRFCRC Sub Menu', 'CRFCRC Instructions', 'manage_options', 'crfcrc-data-sub', 'crfcrc_data_admin_page');
}
function crfcrc_data_admin_page() {
echo "<div class='wrap'><h2>CRFCRC Data and Functions</h2></div>";
}
//END Create Admin menu
I then used the crfcrc-data slug from my function in the show_in_menu section of each CPT to place them under the CRFCRC menu item.
As you can see in the attached screenshot, the CPTs are attached to the CRFCRC menu item, but they are placed in reverse alpha order and before my sub-menu page. What I want is for CRFCRC Instructions to be first, followed by Brags, Dogs, then Members. Is there a way to do this?
Thanks for your help.
It depends on the "parent" page (the crfcrc-data menu), how it's child are sort and added.
When using 'some string' to show as a submenu of a menu page created by a plugin (or code, for that is, as in your case), this item will become the first submenu item, and replace the location of the top-level link.
If this isn't desired, the plugin that creates the menu page needs to set the add_action priority for admin_menu to 9 or lower.
Reference:
https://codex.wordpress.org/Function_Reference/register_post_type
Thanks. I found the following code which does the trick.
add_filter( 'custom_menu_order', 'crfcrc_submenu_order' );
function crfcrc_submenu_order( $menu_ord )
{
global $submenu;
// Enable the next line to see all menu orders
//echo '<div style="padding-left: 10em;"><pre>'.print_r($submenu,true).'</pre></div>';
$arr = array();
$arr[] = $submenu['crfcrc-data'][3];
$arr[] = $submenu['crfcrc-data'][2];
$arr[] = $submenu['crfcrc-data'][1];
$arr[] = $submenu['crfcrc-data'][0];
$submenu['crfcrc-data'] = $arr;
return $menu_ord;
}