Sub menu with a URL parameter and access the page

I want to add the parameter for the submenus, but when I click to the admin page I get the following message:

it throwing Sorry, you are not allowed to access this page.

add_menu_page( 'Main Menu', '', $min_access_cap, 'main-main', array($this, 'main_menu'), $icon_url, 999 );

http://example.fmt/wp-admin/admin.php?page=main-main

add_submenu_page( 'main-menu', sprintf( __( '%1$s ‹ %2$s', 'main-menu' ), $title['page_title'], 'Submenu' ), $title['admin_menu_title'], $min_access_cap, 'page=settings&submenu=page2', array($this, 'sub_menu') );

http://example.fmt/wp-admin/admin.php?page=settings&submenu=page2

I have created the submenu link but the problem it’s now showing the page. It’s showing access denied.

How can I solve this issue?

Thanks

Solutions Collecting From Web of "Sub menu with a URL parameter and access the page"

I have checked your code. You are using incorrect menu-slug in add_submenu_page. Because admin already has page query var which conflicts with your menu slug page=settings&submenu=page2.

I have updated the code.



add_menu_page( 'Main Menu', 'Main Menu Titlw', $min_access_cap, 'main-main', array($this, 'main_menu'), $icon_url, 999 );

add_submenu_page( 'main-menu', sprintf( __( '%1$s ‹ %2$s', 'main-menu' ), $title['page_title'], 'Submenu' ), $title['admin_menu_title'], $min_access_cap, 'submenu/slug', array($this, 'sub_menu') );