• Hy,

    i just want code this:

    Create a custom post type, give it a custom capability and let a custom role only access this.

    So i created a new custom post type called “press” and gave the capability “press_review”, i added a role called “press dude” an gave him all access to only this kind of post type. But its not working…

    add_action( 'init', 'create_my_post_types' );
    
    function create_my_post_types() {
     register_post_type( 'press',
      array(
       'labels' => array(
        'name' => __( 'Press Reviews' ),
        'singular_name' => __( 'Press Review' ),
        'add_new' => __( 'Add New' ),
        'add_new_item' => __( 'Add New Press Review' ),
        'edit' => __( 'Edit' ),
        'edit_item' => __( 'Edit Press Review' ),
        'new_item' => __( 'New Reveiw' ),
        'view' => __( 'View Review' ),
        'view_item' => __( 'View Review' ),
        'search_items' => __( 'Search Press Review' ),
        'not_found' => __( 'No Press Reviews found' ),
        'not_found_in_trash' => __( 'No Press Review found in Trash' ),
        'parent' => __( 'Parent Press Review' ),
        'description' => __( 'A Press Review is a type of content where your Press Reviews are set up.'),
    
        /* Global control over capabilities. */
        'capability_type' => 'press_review',
    
        /* Specific control over capabilities. */
        'capabilities' => array(
        'edit_post' => 'edit_press_review',
        'edit_posts' => 'edit_press_reviews',
        'edit_others_posts' => 'edit_others_press_reviews',
        'publish_posts' => 'publish_press_reviews',
        'read_post' => 'read_press_review',
        'read_private_posts' => 'read_private_press_reviews',
        'delete_post' => 'delete_press_review')
       ),
       'public' => true,
       'show_ui' => true,
       'publicly_queryable' => true,
       'exclude_from_search' => false,
       'query_var' => true,
       'supports' => array( 'title', 'editor' , 'thumbnail' ),
      )
    
     );
    
     add_role('press_dude', 'Press Dude', array(
        'read' => true,
        'edit_press_review' => true,
        'edit_press_reviews' => true,
        'edit_others_press_reviews' => true,
        'publish_press_reviews' => true,
        'read_press_review' => true,
        'read_private_press_reviews' => true,
        'delete_press_review' => true,
            ));
    }

    On login i get:

    You do not have sufficient permissions to access this page.

    Any ideawhat´s wrong in here?

The topic ‘Capability, role and custom post type’ is closed to new replies.