1
votes

I'm battling with a wordpress plugin and custom post type - specifically adding it to a submenu. I have checked the wordpress codex pages, namely: Custom Post Types, Roles and Capabilities and the Add Submenu Codex, which I cannot post a link to as I dont have 10 reputation.

But I'm not finding a way to do this. I assume I'm missing something simple and someone here can assist.

I have a wordpress custom post type called ns_home_page and it is setup as

register_post_type('ns_home_page',
array(
'labels' => array(
'name' => __( 'Home Page' ),
'singular_name' => __( 'Home Page' )
),
'public' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ),
'show_ui' => true,
'show_in_menu' => false,
)
);

Next, I have added it by

add_action('init', array($this, 'create_homepage_items_type')); 

which is calling a method in the class I have created in my plugin. This all works fine. I have added three new posts and they work 100%.

The issue is now I would like to add these to a custom menu in admin.

I have the following code for this:

$page_title = 'Ns Content';
    $menu_title = 'NS Content';
    $capability = 'manage_options';
    $menu_slug = 'ns-content';
    $capability = "manage_options";
    $function = array($this, 'display_admin');
    add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function);

    $submenu_page_title = 'Ns Home Page';
    $submenu_title = 'Home Page';
    $submenu_slug = 'edit.php?post_type=ns_home_page';
    $submenu_function = 'myplugin_help';
    $capability = "publish_posts";
add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);

This creates a menu in my admin with the title "NS Content", and this has two submenu's, "NS Content" and "Home Page". However, the link to the Home Page content type is currently

/wp-admin/admin.php?page=edit.php?post_type=ns_home_page and in order to display my posts, I need the link to be

/wp-admin/edit.php?post_type=ns_home_page Ant idea how to set this link up correctly?

2

2 Answers

0
votes

You need to register custom post type properly, once it is done, functionalities like list, add, edit, trash will be handled by WordPress automatically.

You can refer http://generatewp.com/post-type/ for more info.

0
votes

Take a look at $submenu_slug, replace edit.php?post_type=ns_home_page with just nshomepage and give a try it should work