• Resolved Angelo Rocha

    (@angelorocha)


    Hi folks.

    I have a custom post type and create a submenu page for settings:

    add_action('admin_menu', 'post_type_subpage');
    function post_type_subpage() {
        add_submenu_page(
            'edit.php?post_type=mycustomposttype',
            'Configs',
            'Configs Start Page',
            'edit_post',
            'mypost-configs',
            'post_type_subpage_content' );
    }
    
    function post_type_subpage_content(){
        echo "<h1>Configs...</h1>";
    }

    Is possible insert metaboxes in this menu page? How to?

    https://www.ads-software.com/plugins/cmb2/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Thread Starter Angelo Rocha

    (@angelorocha)

    I tried using this class as an example, but not understand its operation.

    public function add_options_page() {
    		$this->options_page = add_menu_page( $this->title, $this->title, 'manage_options', $this->key, array( $this, 'admin_page_display' ) );
    		// Include CMB CSS in the head to avoid FOUT
    		add_action( "admin_print_styles-{$this->options_page}", array( 'CMB2_hookup', 'enqueue_cmb_css' ) );
    	}

    What is the correct syntax to add a submenu page?

    Plugin Author Justin Sternberg

    (@jtsternberg)

    Replace our add_menu_page and your add_submenu_page code with this:

    $this->options_page = add_submenu_page( 'edit.php?post_type=mycustomposttype', 'Configs', 'Configs Start Page', 'edit_post', $this->key, 'admin_page_display' );

    and it should work fine (with everything else being the same).

    Thread Starter Angelo Rocha

    (@angelorocha)

    Awesome!
    Thanks guy.

    EDIT: Nevermind – solved it.

    Hi! when i make the change for this code:
    $this->options_page = add_submenu_page( 'edit.php?post_type=mycustomposttype', 'Configs', 'Configs Start Page', 'edit_post', $this->key, 'admin_page_display' );

    i get this error, any idea why? or that code is outdated?

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘admin_page_display’ not found or invalid function name in C:\wamp\www\genesis\wp-includes\plugin.php on line 503

    note: both “admin_page_display” (the function call and the function itself) are written exactly the same.

    Best regards ??

    Wait, instead of
    'admin_page_display'
    Should be:
    array( $this, 'admin_page_display' )

    ??

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Glad I decided to refresh the page before I replied. That looks correct to me as well angelmoskera. Glad to hear you found the solution.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Add metabox in submenu page on custom post type’ is closed to new replies.