Having a bit of fun with custom post types.
I use / to generate the following custom post type to record partner organisation records.
Things working:
- custom post type appears on admin menu
- categories and tags on both of them (i may delete them later by clearing taxonomies)
What I can't figure out is why the "Add New" menu item is not appearing ... maybe because it's friday and it's been a long week but I cannot see what i'm missing
Anyone?
/* Add Support for CEP Partner records */
if ( ! function_exists('Partners') ) {
// Register Custom Post Type
function Partners() {
$labels = array(
'name' => _x( 'Partners', 'Post Type General Name', 'cep' ),
'singular_name' => _x( 'Partner', 'Post Type Singular Name', 'cep' ),
'menu_name' => __( 'Partner', 'cep' ),
'parent_item_colon' => __( 'Parent Partner', 'cep' ),
'all_items' => __( 'Partners', 'cep' ),
'view_item' => __( 'View Partner', 'cep' ),
'add_new_item' => __( 'Add New Partner', 'cep' ),
'add_new' => __( 'New Partner', 'cep' ),
'edit_item' => __( 'Edit Partner', 'cep' ),
'update_item' => __( 'Update Partner', 'cep' ),
'search_items' => __( 'Search Partner', 'cep' ),
'not_found' => __( 'No Partners found', 'cep' ),
'not_found_in_trash' => __( 'No Partners found in Trash', 'cep' ),
);
$rewrite = array(
'slug' => 'cep-partners',
'with_front' => true,
'pages' => true,
'feeds' => true,
);
$capabilities = array(
'edit_post' => 'edit_partner',
'read_post' => 'read_post',
'delete_post' => 'delete_partner',
'edit_posts' => 'edit_partners',
'edit_others_posts' => 'edit_others_partners',
'publish_posts' => 'publish_partners',
'read_private_posts' => 'read_private_partners',
);
$args = array(
'label' => __( 'partners', 'cep' ),
'description' => __( 'CEP Partner Organisations', 'cep' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'post-formats', ),
'taxonomies' => array( 'category', 'post_tag' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => '',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'query_var' => 'partners',
'rewrite' => $rewrite,
'capabilities' => $capabilities,
);
register_post_type( 'partners', $args );
}
// Hook into the 'init' action
add_action( 'init', 'Partners', 0 );
}
Having a bit of fun with custom post types.
I use http://generatewp/ to generate the following custom post type to record partner organisation records.
Things working:
- custom post type appears on admin menu
- categories and tags on both of them (i may delete them later by clearing taxonomies)
What I can't figure out is why the "Add New" menu item is not appearing ... maybe because it's friday and it's been a long week but I cannot see what i'm missing
Anyone?
/* Add Support for CEP Partner records */
if ( ! function_exists('Partners') ) {
// Register Custom Post Type
function Partners() {
$labels = array(
'name' => _x( 'Partners', 'Post Type General Name', 'cep' ),
'singular_name' => _x( 'Partner', 'Post Type Singular Name', 'cep' ),
'menu_name' => __( 'Partner', 'cep' ),
'parent_item_colon' => __( 'Parent Partner', 'cep' ),
'all_items' => __( 'Partners', 'cep' ),
'view_item' => __( 'View Partner', 'cep' ),
'add_new_item' => __( 'Add New Partner', 'cep' ),
'add_new' => __( 'New Partner', 'cep' ),
'edit_item' => __( 'Edit Partner', 'cep' ),
'update_item' => __( 'Update Partner', 'cep' ),
'search_items' => __( 'Search Partner', 'cep' ),
'not_found' => __( 'No Partners found', 'cep' ),
'not_found_in_trash' => __( 'No Partners found in Trash', 'cep' ),
);
$rewrite = array(
'slug' => 'cep-partners',
'with_front' => true,
'pages' => true,
'feeds' => true,
);
$capabilities = array(
'edit_post' => 'edit_partner',
'read_post' => 'read_post',
'delete_post' => 'delete_partner',
'edit_posts' => 'edit_partners',
'edit_others_posts' => 'edit_others_partners',
'publish_posts' => 'publish_partners',
'read_private_posts' => 'read_private_partners',
);
$args = array(
'label' => __( 'partners', 'cep' ),
'description' => __( 'CEP Partner Organisations', 'cep' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'post-formats', ),
'taxonomies' => array( 'category', 'post_tag' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => '',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'query_var' => 'partners',
'rewrite' => $rewrite,
'capabilities' => $capabilities,
);
register_post_type( 'partners', $args );
}
// Hook into the 'init' action
add_action( 'init', 'Partners', 0 );
}
Share
Improve this question
edited Aug 26, 2013 at 21:24
s_ha_dum
65.6k13 gold badges84 silver badges174 bronze badges
asked Aug 26, 2013 at 21:16
user37166user37166
11 bronze badge
1
|
1 Answer
Reset to default 1You can't see the menus you expect because the capabilities have not been registered. These:
$capabilities = array(
'edit_post' => 'edit_partner',
'read_post' => 'read_post',
'delete_post' => 'delete_partner',
'edit_posts' => 'edit_partners',
'edit_others_posts' => 'edit_others_partners',
'publish_posts' => 'publish_partners',
'read_private_posts' => 'read_private_partners',
);
All of those capabilities with "partner" in them do not exist by default. For a quick test comment that out and you should see the menus. Change "partner" to "post" and things should be editable by the same people who can edit posts (I believe that is the default behavior if you don't pass any capability argument, but I'd have to test it or look it up to be sure.)
You can, of course, create those capabilities, if you'd rather go that route.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744785497a4593598.html
publish_partners
? – Milo Commented Aug 26, 2013 at 21:32