• Hey folks!

    I recently ran into a weird problem with registering a custom post type through a plugin on a fresh WP system: When activating the plugin as the first thing after installing, the custom post type wouldn’t show under Appearance->Menus. Normally custom post types show in the menu item box on the left (if not disabled when calling register_post_type), but in this case the entry was missing. Deactivating and re-activating the plugin didn’t help. Setting the show_in_nav_menus parameter explicitely to true didn’t help either. After fiddeling around with the code for a while I figured changing the post_type parameter of the register_post_type function will add the CPT to the menu item box.

    In the end it became clear that there wasn’t a problem with the plugin code, but something super odd: when activating the plugin after loading the Appearance->Menus page at least once, the new custom post type is added perfectly fine to the menu item box. It seems as if on first load of the Menus page WP does soemthing that is vitally important to integrate CPTs into the menu configuration interface.

    As this is such an odd behaviour, I considered sharing it and maybe saving someone else a headache. I didn’t find anything on the forum…

    Here’s the plugin code I used for testing:

    add_action( 'init', 'create_cp_A', 8 );
    
    function create_cp_A() {
    
    	$labels = array(
    		'name'               => _x( 'A Posts', 'post type general name' ),
    		'singular_name'      => _x( 'A Post', 'post type singular name' ),
    		'add_new'            => _x( 'Add New', 'book' ),
    		'add_new_item'       => __( 'Add New A Post' ),
    		'edit_item'          => __( 'Edit A Post' ),
    		'new_item'           => __( 'New A Post' ),
    		'all_items'          => __( 'All A Posts' ),
    		'view_item'          => __( 'View A Post' ),
    		'search_items'       => __( 'Search A Posts' ),
    		'not_found'          => __( 'No A Posts found' ),
    		'not_found_in_trash' => __( 'No A Posts found in the Trash' ),
    		'parent_item_colon'  => '',
    		'menu_name'          => 'A Posts'
    	);
    	$args = array(
    		'labels'        		=> $labels,
    		'description'   		=> 'CP for testing purposes',
    		'public'        		=> true,
    		'menu_position' 		=> 5,
    		'supports'      		=> array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'revisions' ),
    		'has_archive'   		=> true,
    		'exclude_from_search'		=> false
    	);
    	register_post_type( 'cp_A', $args );
    }

    Cheers

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    This is intended behavior, believe it or not. All new users are intentionally only shown pages, links, and categories. They need to use the screen options to see more. Your CPT should be there, only hidden.

    Thankfully, registering CPTs causes them to show up by default to existing users. I frequently forget to check screen options and assume something is wrong when the expected doesn’t initially show up.

Viewing 1 replies (of 1 total)
  • The topic ‘Adding Custom Post Type on freshly installed WP’ is closed to new replies.