Adding Meta Box to Specific Submenu Page

I've created this page:

function wpdocs_register_my_setting() {
    add_submenu_page(
        'edit.php?post_type=task',
        'View Tasks',
        'View Tasks',
        'manage_options',
        'view-tasks',
        'view_tasks_submenu_page_callback'
    );
}

function view_tasks_submenu_page_callback() {
    // html
}
add_action( 'admin_menu', 'wpdocs_register_my_setting' );

And I want to add a meta box to this page only.

function cd_meta_box_add() {
    add_meta_box( 'in-progress-metabox', 'In Progress', 'render_task_in_progress_metabox', 'task', 'normal', 'high' );
}
function render_task_in_progress_metabox() {
    // html
}
add_action( 'add_meta_boxes', 'cd_meta_box_add' );

But I cannot seem to find the correct answer for this. Again, I only want to add this meta box to this specific page. I've seen people talk about needing to use do_meta_boxes but it doesn't really make sense.

Topic add-submenu-page sub-menu metabox Wordpress

Category Web


I think for this you want to go with Wordpress Setting API.

If you prefer meta box. You have to add a do_action in your function which render the page (view_tasks_submenu_page_callback).

do_action( 'add_meta_boxes', $hook_id );

And add do_meta_boxes($hook_id, $context, null) where you want your meta boxes appear.

replace $hook_id by the fourth parameter of add_meta_box function.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.