Maximum number of Custom Post Types – (register_post_type)
-
Hi Guys,
Does anyone know if there is a maximum number of Custom post Types that can be placed in the array? I am currently passing 5, however only 4 will show in the admin section.
add_action('init', 'custom_post_types_register'); function custom_post_types_register() { $args = array(...); register_post_type( 'NAME1' , $args ); $args2 = array(...); register_post_type( 'NAME2' , $args2 ); $args3 = array(...); register_post_type( 'NAME3' , $args3 ); $args4 = array(...); register_post_type( 'NAME4' , $args4 ); $args5 = array(...); register_post_type( 'NAME5' , $args5 ); }
Thanks,
Carlo
-
Well you are not actually placing them in an array, each post type is seperate and simply uses an
$args
array to pass the arguments.I have 8 Post Types on a site and they work fine – perhaps the one that is not displaying has an error in the arguments?
Of course.. sorry for the wrong wording!
I dont mean to be cheeky but could you look at the following and let me know if you spot any errors ?? I honestly cannot see it!
add_action('init', 'custom_post_types_register'); function custom_post_types_register() { $args = array( 'label' => __('Info Centre'), 'singular_label' => __('Info Centre'), 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => true, 'rewrite' => array("slug" => "information-centre",'with_front' => true), // Permalinks format 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail', 'page-attributes' ), 'add_new' => __( 'Add New' ), 'add_new_item' => __( 'Add New Info' ), 'edit' => __( 'Edit' ), 'edit_item' => __( 'Edit Info' ), 'new_item' => __( 'New Info' ), 'view' => __( 'View Info' ), 'view_item' => __( 'View Info' ), 'search_items' => __( 'Search Info Centre' ), 'not_found' => __( 'No info found' ), 'not_found_in_trash' => __( 'No info found in Trash' ), 'parent' => __( 'Parent Info' ), 'menu_position' =>__( 20 ), // 'menu_icon' =>__( get_stylesheet_directory_uri() . '/assets/images/admin/info-centre-icon.png' ), ); register_post_type( 'info' , $args ); $args2 = array( 'label' => __('Services'), 'singular_label' => __('Services'), 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => true, 'rewrite' => array("slug" => "services",'with_front' => true), // Permalinks format 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail', 'page-attributes' ), 'add_new' => __( 'Add New' ), 'add_new_item' => __( 'Add New Service' ), 'edit' => __( 'Edit' ), 'edit_item' => __( 'Edit Service' ), 'new_item' => __( 'New Service' ), 'view' => __( 'View Service' ), 'view_item' => __( 'View Service' ), 'search_items' => __( 'Search Services' ), 'not_found' => __( 'No service found' ), 'not_found_in_trash' => __( 'No service found in Trash' ), 'parent' => __( 'Parent Service' ), 'menu_position' =>__( 21 ), // 'menu_icon' =>__( get_stylesheet_directory_uri() . '/assets/images/admin/services-icon.png' ), ); register_post_type( 'services' , $args2 ); $args3 = array( 'label' => __('Agencies'), 'singular_label' => __('Agencies'), 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => true, 'rewrite' => array("slug" => "agencies",'with_front' => true), // Permalinks format 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail', 'page-attributes' ), 'add_new' => __( 'Add New' ), 'add_new_item' => __( 'Add New Agencies' ), 'edit' => __( 'Edit' ), 'edit_item' => __( 'Edit Agencies' ), 'new_item' => __( 'New Agencies' ), 'view' => __( 'View Agencies' ), 'view_item' => __( 'View Agencies' ), 'search_items' => __( 'Search Agencies' ), 'not_found' => __( 'No agencies found' ), 'not_found_in_trash' => __( 'No agencies found in Trash' ), 'parent' => __( 'Parent Agencies' ), 'menu_position' =>__( 22 ), // 'menu_icon' =>__( get_stylesheet_directory_uri() . '/assets/images/admin/services-icon.png' ), ); register_post_type( 'agencies' , $args3 ); $args4 = array( 'label' => __('Contact'), 'singular_label' => __('Contact'), 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => true, 'rewrite' => array("slug" => "contact",'with_front' => true), // Permalinks format 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail', 'page-attributes' ), 'add_new' => __( 'Add New' ), 'add_new_item' => __( 'Add New Contact' ), 'edit' => __( 'Edit' ), 'edit_item' => __( 'Edit Contact' ), 'new_item' => __( 'New Contact' ), 'view' => __( 'View Contact' ), 'view_item' => __( 'View Contact' ), 'search_items' => __( 'Search Contact' ), 'not_found' => __( 'No contact found' ), 'not_found_in_trash' => __( 'No contact found in Trash' ), 'parent' => __( 'Parent Contact' ), 'menu_position' =>__( 23 ), // 'menu_icon' =>__( get_stylesheet_directory_uri() . '/assets/images/admin/services-icon.png' ), ); register_post_type( 'contact' , $args4 ); $args5 = array( 'label' => __('Mentoring'), 'singular_label' => __('Mentoring'), 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => true, 'rewrite' => array("slug" => "mentoring",'with_front' => true), // Permalinks format 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail', 'page-attributes' ), 'add_new' => __( 'Add New' ), 'add_new_item' => __( 'Add New Mentoring' ), 'edit' => __( 'Edit' ), 'edit_item' => __( 'Edit Mentoring' ), 'new_item' => __( 'New Mentoring' ), 'view' => __( 'View Mentoring' ), 'view_item' => __( 'View Mentoring' ), 'search_items' => __( 'Search Mentoring' ), 'not_found' => __( 'No Mentoring found' ), 'not_found_in_trash' => __( 'No Mentoring found in Trash' ), 'parent' => __( 'Parent Mentoring' ), 'menu_position' =>__( 24 ), // 'menu_icon' =>__( get_stylesheet_directory_uri() . '/assets/images/admin/services-icon.png' ), ); register_post_type( 'mentoring' , $args5 ); }
Thanks!
I have even switched 4 and 5 around and the fifth one never displays
Do you mean you have swapped the
$args
around?I use the code below for mine, perhaps try that as I can not se anything obviously wrong (and WP is quite clever in that it will usually only ignore the one argument that is wrong, rather than miss the whole function).
Maybe also try removing the ‘menu_position’ argument and seeing if WP will add the Post Type then, to the bottom of the menu?
/** * Initiate Our People function * * Function declares all $labels and $args and registers the Post Type */ function initiate_our_people(){ $labels = array( 'name' => _x('Our People', 'post type general name'), 'singular_name' => _x('Member of Staff', 'post type singular name'), 'add_new' => _x('Add New', 'Member of Staff'), 'add_new_item' => __('Add New Member of Staff'), 'edit_item' => __('Edit Member of Staff'), 'new_item' => __('New Member of Staff'), 'view_item' => __('View Member of Staff'), 'search_items' => __('Search Our People'), 'not_found' => __('No Members of Staff found'), 'not_found_in_trash' => __('No Members of Staff found in Trash'), 'parent_item_colon' => '' ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, '_builtin' => false, 'query_var' => true, 'rewrite' => array('slug' => 'fee-earners'), 'capability_type' => 'page', 'hierarchical' => false, 'menu_position' => 8, 'supports' => array('title','editor','author','thumbnail','custom-fields') ); register_post_type('dd_our-people',$args); }
Thinking about it – I do use a different script to initiate every Post Type, and there for a different
add_action()
– not sure if it makes a difference but maybe worth a try, i.e. –add_action('init', 'register_info_centre'); add_action('init', 'register_services'); function register_info_centre(){ $args = array( 'label' => __('Info Centre'), 'singular_label' => __('Info Centre'), 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => true, 'rewrite' => array("slug" => "information-centre",'with_front' => true), // Permalinks format 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail', 'page-attributes' ), 'add_new' => __( 'Add New' ), 'add_new_item' => __( 'Add New Info' ), 'edit' => __( 'Edit' ), 'edit_item' => __( 'Edit Info' ), 'new_item' => __( 'New Info' ), 'view' => __( 'View Info' ), 'view_item' => __( 'View Info' ), 'search_items' => __( 'Search Info Centre' ), 'not_found' => __( 'No info found' ), 'not_found_in_trash' => __( 'No info found in Trash' ), 'parent' => __( 'Parent Info' ), 'menu_position' =>__( 20 ), // 'menu_icon' =>__( get_stylesheet_directory_uri() . '/assets/images/admin/info-centre-icon.png' ), ); register_post_type( 'info' , $args ); } function register_services(){ $args2 = array( 'label' => __('Services'), 'singular_label' => __('Services'), 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => true, 'rewrite' => array("slug" => "services",'with_front' => true), // Permalinks format 'supports' => array( 'title', 'editor', 'excerpt', 'custom-fields', 'thumbnail', 'page-attributes' ), 'add_new' => __( 'Add New' ), 'add_new_item' => __( 'Add New Service' ), 'edit' => __( 'Edit' ), 'edit_item' => __( 'Edit Service' ), 'new_item' => __( 'New Service' ), 'view' => __( 'View Service' ), 'view_item' => __( 'View Service' ), 'search_items' => __( 'Search Services' ), 'not_found' => __( 'No service found' ), 'not_found_in_trash' => __( 'No service found in Trash' ), 'parent' => __( 'Parent Service' ), 'menu_position' =>__( 21 ), // 'menu_icon' =>__( get_stylesheet_directory_uri() . '/assets/images/admin/services-icon.png' ), ); register_post_type( 'services' , $args2 ); } etc...
Thanks for your help DB!
Turns out it was the menu position, removed it and viola!
Good news. If you want to take it to the next step, you can also edit the postion of the standard WP menus using the
global $menu
.The below example would remove the ‘Posts’ menu (don’t know about you, but I didn’t want that after I had added Custom Post Types) and will then move the Pages Menu to postion 30 (after comments) –
add_action('admin_head', 'edit_admin_menu'); function edit_admin_menu(){ global $menu; // Change the order of the standard WP menu items unset($menu[5]); // Unset Posts $menu[30] = $menu[20]; // Copy Pages from position 20 to position 30 (Below Comments) unset($menu[20]); // Unset Pages (from original position) }
That is most awesome!
Thanks again
Thanks for the help on this – I was having the same problem of disappearing menu items. But this seems like a bug. Why would the menu_position parameter, if applied, limit items in the admin menu? Any thoughts?
Hi Stunnaboi,
No, this is not a bug.
Probably one is misusing the menu_position parameter, as in
$menu[99] = 'foo';
then later uses the same menu_position value, as in
$menu[99] = 'bar';
Surely the ‘foo’ value will be replaced by ‘bar’, hence the so called
missing item.Does it make sense now?
Also,
menu_position' =>__( 21 ),
is wrong. It will trigger the translation engine, but this should really be only a number.
So,
menu_position' => 21,
is the correct usage.
Regards,
Gabriel
- The topic ‘Maximum number of Custom Post Types – (register_post_type)’ is closed to new replies.