0

I want to use custom post type in my web app and want to use that url in my plugin menu. I have created custom post type like this.

register_post_type( 'reserve',
    array(
        'labels' => array(
            'name' => __( 'Reserves' ),
            'singular_name' => __( 'Reserve' ),
            'all_items' => __( 'All Reserves' ),
            'add_new' => __( 'Add Reserve' ),
            'add_new_item' => __( 'Add New Reserve' ),
            'edit' => __( 'Edit'),
            'edit_item' => __( 'Edit Reserve' ),
            'new_item' => __( 'New Reserve'),
            'view' => __( 'View Reserve'),
            'view_item' => __( 'View Reserve'),
            'search_items' => __( 'Search Reserves'),
            'not_found' => __( 'No Reserves found' ),
            'not_found_in_trash' => __( 'No Reserves found in trash' ),
            'parent' => __( 'Parent Reserve')
        ),      

    'description' => __( 'This is where you can add new Reserves' ),
    'public' => true,
    'show_ui' => false,
    'capability_type' => 'page',
    'publicly_queryable' => true,
    'exclude_from_search' => false,
    'hierarchical' => true,
    'rewrite' => array( 'slug' => 'reserves', 'with_front' => false ),
    'query_var' => true,
    'supports' => array( 'title', 'editor', 'thumbnail', 'comments', 'excerpt',/*, 'page-attributes'*/ ),
    'has_archive' => true,
    'show_in_nav_menus' => true
    )
);

Notice that I have set show_ui as false so that my new custom type wont be displayed on admin sidebar. Now I am creating a my plugin menu as following.

$topslug = 'reserve/admin'; 
add_menu_page('Reserve Overview', 'Reservation', 'view_reservation_plugin', $topslug, 'show_start_page',RESERVE_URL.'images/menu_icon.png');
add_submenu_page($topslug, 'RESERVE', 'Reserve Builder', 'view_reservation_plugin', 'reserve/manage_reserve', 'show_manage_reserves');

From above code you can find that I have created a menu as Reservation having two submenus 1) Reserve Overview 2) Reserve Builder.

Now my issue is I want to change my URL of Reserve Builder.

Currently its 'admin.php?page=reserve/manage_reserves'. I want to change it like 'edit.php?post_type=reserve' so that i can use wordpress inbuilt facility.

Say if I am passing 'edit.php?post_type=reserve' in add_submenu_page('edit.php?post_type=reserve', 'RESERVE', 'Reserve Builder', 'view_reservation_plugin', 'reserve/manage_reserve', 'show_manage_reserves').Menu gets disappeared. TIA.

3
  • Why not just remove 'show_ui' => false and use it? Add submenu pages to that post type and you can use the built-in WP editor, meta boxes for customization, etc.
    – Jared
    Mar 12, 2012 at 10:12
  • Actually I don't want to make two menus in my custom plugin. All menu should go under one main tab. Mar 12, 2012 at 10:21
  • You can add submenu pages to custom post types with add_submenu_page(). I have done it with many plugins I've developed. For Custom Post Types: add_submenu_page('edit.php?post_type=your_post_type',...).. Or am I understanding it wrong? :)
    – Jared
    Mar 12, 2012 at 10:34

1 Answer 1

0

You're passing edit.php?post_type=reserve as first parameter and that should be parent menu slug. Instead pass it as menu_slug parameter, see code snippet below.

add_submenu_page( 
    'reserve/admin', 
    'Reserve',
    'Reserve Builder', 
    'view_reservation_plugin', // $capability
    'edit.php?post_type=reserve' 
);
2
  • You are life saver.... Mar 12, 2012 at 11:07
  • Actually I have tried in this manner but i dnt know wht was my mistake anyways you are awesome.. Mar 12, 2012 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.