WordPress custom post type doesn’t show up in left menu bar on specific site

I have a bit of a problem. I’ve developed a plugin and there are few ppl who are using it. However, one reported a weird problem. Custom post menu doesn’t show up for him (it shows up on my test site and other people do not have any problems either). Now, pages from menu are actually there, you can reach them by using links like https://domain.com/wp-admin/edit.php?post_type=custom-post-type and
https://domain.com/wp-admin/post-new.php?post_type=custom-post-type, it just doesn’t show up in the menu.

Custom post type is registered as follows:

Read More
register_post_type('custom-post-type', array(
'label'=>"Custom Post Type Name",
'supports'=>array('title'),
'public'=>false,
'show_ui'=>true,
'show_in_menu'=>true,
'rewrite'=>false,
'menu_icon'=>plugin_dir_url(__FILE__).'res/menu_icon.png',
'query_var'=>false,
'publicly_queryable'=>false,
'menu_position'=>80,
'exclude_from_search'=>true
));

Any idea what can be causing this? I’m at my wit’s end.

Related posts

Leave a Reply

2 comments

  1. Unfortunately (as you have discovered), WordPress handles menu ordering in a silly way. To make things worse, float values for position are no longer allowed.

    In order to avoid conflicts completely, you can try to grab the current menu locations, and then set your directly above or below it. I haven’t tested this, but something like the following should work:

    global $menu;  // An array of all menu positions
    
    $my_menu_position = 80;
    
    // While another menu item is in your desired position
    while ( !empty( $menu[$my_menu_position] ) ) {
        // Increment the menu position by one
        ++$my_menu_position;
    }
    

    You can then use $my_menu_position in place of the current menu position integer you are using.

  2. I had this issue too when building a multisite. I think that WordPress should adjust this as I actually overlooked this twice, due to lack of notifications.

    Once I’ve created a new location (site), I didn’t see any of the custom post types being registered.

    To fix it, all I had to do is go into Themes in the admin panel & activate my custom theme.

    Why do I think WP should change something?

    Because the ‘Active’ theme did not actually exist! The error stating that directory ‘twentyfifteen’ did not exist only showed up on the Themes page. If it was only present on the dashboard… But hey, I will remember now 🙂