• I am learning WordPress Plugin development. I need to create a Add New like this image .

    My code is like below.

    public function register_custom_post_type() {
    
    $supports = ['title'];
    
    $labels = [
    
    'name' => __( 'News', 'wpwi' ),
    
    'singular_name' => __( 'News', 'wpwi' ),
    
    'name_admin_bar' => __( 'News', 'wpwi' ),
    
    'add_new' => __( 'Add New', 'wpwi' ),
    
    'add_new_item' => __( 'Add New News', 'wpwi' ),
    
    'new_item' => __( 'New News', 'wpwi' ),
    
    'edit_item' => __( 'Edit News', 'wpwi' ),
    
    'all_items' => __( 'News', 'wpwi' ),
    
    'search_items' => __( 'Search News', 'wpwi' ),
    
    'not_found' => __( 'No News Found.', 'wpwi' ),
    
    ];
    
    $args = [
    
    'public' => true,
    
    'show_ui' => true,
    
    'supports' => $supports,
    
    'labels' => $labels,
    
    'description' => 'News Information',
    
    'has_archive' => true,
    
    'exclude_from_search' => false,
    
    'show_in_menu' => 'news_info',
    
    ];
    
    register_post_type( 'news_info', $args );
    
    }
    
    public function admin_menu() {
    
    add_menu_page( __( 'News Information', 'wpwi' ), 'News Info', 'manage_options', 'news_info', [$this, 'api_key_page'], 'dashicons-info-outline', 30 );
    
    add_submenu_page( 'news_info', __( 'News Information', 'wpwi' ), 'API Key', 'manage_options', 'news_info_page', [$this, 'api_key_page'], 0 );
    
    add_submenu_page( 'news_info', __( 'News Information', 'wpwi' ), 'Add News', 'manage_options', 'news_info', 'call_back_function', 1 );
    }

    But I can’t see Add New.

    • This topic was modified 1 year, 10 months ago by mabufoysal.
    • This topic was modified 1 year, 10 months ago by mabufoysal.
    • This topic was modified 1 year, 10 months ago by mabufoysal.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Registering the post type would be quite sufficient. You don’t need to build your own menu.

    Minimal example:

    function register_custom_post_type() {
        $supports = ['title'];
        $labels = [
            'name' => __( 'News', 'wpwi' ),
            'singular_name' => __( 'News', 'wpwi' ),
            'name_admin_bar' => __( 'News', 'wpwi' ),
            'add_new' => __( 'Add New', 'wpwi' ),
            'add_new_item' => __( 'Add New News', 'wpwi' ),
            'new_item' => __( 'New News', 'wpwi' ),
            'edit_item' => __( 'Edit News', 'wpwi' ),
            'all_items' => __( 'News', 'wpwi' ),
            'search_items' => __( 'Search News', 'wpwi' ),
            'not_found' => __( 'No News Found.', 'wpwi' ),
        ];
    
        $args = [
            'public' => true,
            'show_ui' => true,
            'supports' => $supports,
            'labels' => $labels,
            'description' => 'News Information',
            'has_archive' => true,
            'exclude_from_search' => false,
            'show_in_menu' => true,
        ];
        register_post_type( 'news_info', $args );
    }
    add_action('init', 'register_custom_post_type');
    Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @threadi. I would like to show menu like below.

    API Key
    Add New
    News Infos

    Then you would have to add to the menu that the Post Type creates as well as reorder it.

    Adding is possible via https://developer.www.ads-software.com/reference/functions/add_submenu_page/ by specifying your Custom Post Type as parent_slug.

    Reordering is done via https://developer.www.ads-software.com/reference/hooks/custom_menu_order/

    Thread Starter mabufoysal

    (@mabufoysal)

    Thanks @threadi . If you check my Code you can find that I created API Key and News Infos . But I couldn’t create Add New. Could you please help me in this regard ?

    Add New is created by wordpress for you if you set show_in_menu to true in your Custom Post Type and set the capabilities to allow your user to see and use that. Take a look at https://developer.www.ads-software.com/reference/functions/register_post_type/ for this.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add New for Admin Menu’ is closed to new replies.