Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have the following custom post type that I am using on one of my sites:

function careers_post_type() {

    $labels = array(
        'name'                => _x( 'Careers', 'Post Type General Name', 'text_domain' ),
        'singular_name'       => _x( 'Career', 'Post Type Singular Name', 'text_domain' ),
        'menu_name'           => __( 'Careers', 'text_domain' ),
        'parent_item_colon'   => __( 'Parent career:', 'text_domain' ),
        'all_items'           => __( 'All careers', 'text_domain' ),
        'view_item'           => __( 'View career', 'text_domain' ),
        'add_new_item'        => __( 'Add New career', 'text_domain' ),
        'add_new'             => __( 'New career', 'text_domain' ),
        'edit_item'           => __( 'Edit career', 'text_domain' ),
        'update_item'         => __( 'Update career', 'text_domain' ),
        'search_items'        => __( 'Search careers', 'text_domain' ),
        'not_found'           => __( 'No careers found', 'text_domain' ),
        'not_found_in_trash'  => __( 'No careers found in Trash', 'text_domain' ),
    );
    $args = array(
        'label'               => __( 'career', 'text_domain' ),
        'description'         => __( 'career information pages', 'text_domain' ),
        'labels'              => $labels,
        'supports'            => array( ),
        'taxonomies'          => array( ),
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type' => 'post',
    );
    register_post_type( 'career', $args );

}

The sucker works beautifully. However I want to add a custom capability to it. I used this tutorial: http://justintadlock.com/archives/2010/07/10/meta-capabilities-for-custom-post-types Once I make the code this, it stops working:

// Register Custom Post Type
function careers_post_type() {

    $labels = array(
        'name'                => _x( 'Careers', 'Post Type General Name', 'text_domain' ),
        'singular_name'       => _x( 'Career', 'Post Type Singular Name', 'text_domain' ),
        'menu_name'           => __( 'Careers', 'text_domain' ),
        'parent_item_colon'   => __( 'Parent career:', 'text_domain' ),
        'all_items'           => __( 'All careers', 'text_domain' ),
        'view_item'           => __( 'View career', 'text_domain' ),
        'add_new_item'        => __( 'Add New career', 'text_domain' ),
        'add_new'             => __( 'New career', 'text_domain' ),
        'edit_item'           => __( 'Edit career', 'text_domain' ),
        'update_item'         => __( 'Update career', 'text_domain' ),
        'search_items'        => __( 'Search careers', 'text_domain' ),
        'not_found'           => __( 'No careers found', 'text_domain' ),
        'not_found_in_trash'  => __( 'No careers found in Trash', 'text_domain' ),
    );
    $args = array(
        'label'               => __( 'career', 'text_domain' ),
        'description'         => __( 'career information pages', 'text_domain' ),
        'labels'              => $labels,
        'supports'            => array( ),
        'taxonomies'          => array( ),
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type' => 'career_editor',
        'capabilities' => array(
            'publish_posts' => 'publish_career',
            'edit_posts' => 'edit_career',
            'edit_others_posts' => 'edit_others_career',
            'delete_posts' => 'delete_career',
            'delete_others_posts' => 'delete_others_career',
            'read_private_posts' => 'read_private_career',
            'edit_post' => 'edit_career',
            'delete_post' => 'delete_career',
            'read_post' => 'read_career',
        ),
    );
    register_post_type( 'career', $args );

}

I even tried taking the capabilities array out and the content type still vanishes. What am I doing wrong?

share|improve this question
    
Did you check to make sure your user role has those new capabilities? –  Eric Allen Sep 20 '13 at 21:07
add comment

2 Answers

'capability_type' is an argument that must be a valid post type.

So, or you use one of default post types (post, page) or once you have defined your own capabilities array you have to use your own post type.

So, using:

....
'capability_type' => 'career'
....

your code should work.

However, once you defined all the capability it should work also without setting any 'capability_type' at all.

share|improve this answer
add comment

You need to add the capabilites to some existing role or add you own user role.

For example:

    add_role('career_editor', 'Carreer Editor', array (
        'publish_career'        => true,
        'edit_career'           => true,
        'edit_others_careerr'   => true,
        'delete_career'         => true,
        'delete_others_career'  => true,
        'read_career'           => true,
        'edit_career'           => true,
        'delete_career'         => true,
        'read_career'           => true,
        'read_private_carreer'  => true,
        'read'                  => true,
   ));

Now we have a new user role, career_editor, with assgined custom capabilites of our custom post type. Now you must have a user with the role career_editor assigned.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.