Home › Forums › Backend Issues (wp-admin) › Custom options page with (custom post-type) child menu shows top level menu item
I have the following options page.
function noknok_wmp_add_options_page() {
acf_add_options_page( [
'page_title' => __( 'NOKNOK Woocommerce Marketing Platform Settings', NOKNOK_WMP_TEXT_DOMAIN ),
'menu_title' => __( 'NOKNOK WMP', NOKNOK_WMP_TEXT_DOMAIN ),
'update_button' => __( 'Save & Sync', NOKNOK_WMP_TEXT_DOMAIN ),
'menu_slug' => 'noknok-wmp-settings',
'redirect' => false,
'capability' => 'edit_posts',
'position' => '3',
'icon_url' => NOKNOK_WMP_URL . '/assets/image/icon.png'
] );
}
add_action( 'acf/init', 'noknok_wmp_add_options_page' );
And the following custom post type which I wish to be a sub-menu item of this navigation.
register_post_type( self::ROLE_PROFILE_POST_TYPE, [
'labels' => $labels = array_merge(
noknok_wmp_post_type_labels( 'Mailerlite Role Sync Profile', 'Mailerlite Role Sync Profiles' ), [
'menu_name' => 'Role Profiles',
'menu_admin_bar' => 'Role Profiles',
'all_items' => 'Role Profiles'
]
),
'description' => "Adds support for Customer Surveys that can be embedded on pages using shortcodes",
'public' => false,
'hierarchical' => true,
'exclude_from_search' => true,
'publicly_queryable' => false,
'show_ui' => true,
'show_in_menu' => 'noknok-wmp-settings',
"show_in_nav_menus" => false,
'show_in_admin_bar' => false,
'capability_type' => 'page',
'supports' => false
] );
This results in the following menu structure
NOKNOK WMP -> edit.php?post_type=ml_role_profile
– Role Profiles -> edit.php?post_type=ml_role_profile
When the post type is not a sub menu item the top level navigation URL works fine although for some strange reason the moment I add a child menu of a post type it no longer functions correctly. Any help appreciated
Kind-of fixed, WordPress will automatically assign the topmost sub-menu item as the URL for the main menu item. I fixed this by adding another settings menu as the topmost sub-menu item that redirects to the options page. It’s kinda messy but it works eh…. Open to anymore suggestions.
add_action( 'admin_menu', function() {
array_unshift( $GLOBALS['submenu']['noknok-wmp-settings'], [
'Settings',
'edit_pages',
'admin.php?page=noknok-wmp-settings'
]);
}, 1000 );
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.