1

I have this already coded project which has a custom post type with a certain behavior: it is only a single post and admins/editors/authors can only edit its content. it's content is a custom data table. administrators and editors can edit just fine. i want Authors to be able to edit this single post as well but i can't seem to be able to find out how. the code is this:

add_action('init', 'register_post_types');
    function register_post_types(){

    register_post_type('post_type_uo', array(
            'labels' => array(
            'name'               => 'uo Articles', 
            'singular_name'      => 'uo', 
            'add_new'            => 'Add uo', 
            'edit_item'          => 'Edit Post', 
            'view_item'          => 'View Post', 
            'search_items'       => 'Find Post', 
            'not_found'          => 'Not Found', 
            'not_found_in_trash' => 'Not Found', 
            'parent_item_colon'  => '', 
            'menu_name'          => 'uo', 
        ),
    'public' => true, 
    'menu_position' => 4, 
    'exclude_from_search' => true,  
    'has_archive' => false,  
    'rewrite' => array('slug' => 'daily-uo'), 
    'taxonomies'    => array( 'dailies' , 'category'),
    'menu_icon'     => 'dashicons-chart-line', // custom icon
    'capabilities' => array('create_posts'  => false,),
    'map_meta_cap' => true,
    'supports'      => array('title')
    ));
    }

i tried to add a capabilities array and then installed "Members" plugin.

'capabilities' => array(
        'create_posts' => 'do_not_allow', // false < WP 4.5, credit @Ewout
        'read_posts' => 'read_uos',
        'edit_post' => 'edit_uo',
        'edit_posts' => 'edit_uos',
        'published_posts' => 'publish_uo',
        'edit_published_posts' => 'edit_uo_p',
        'edit_others_posts ' => 'edit_uo_others'
      ),

i can see the capabilities in plugin's roles page and select them but still no edit access for users with the Athor role.

Finally i made a new role -uo_Author- via the plugin giving the correct(??) permissions but still no luck

any ideas?

1 Answer 1

0

Register "dailies" as a taxonomy.

The Codex for "register post type" says "even if you register a taxonomy while creating the post type, you must still explicitly register and define the taxonomy using register_taxonomy()."

PS: I would have added this as a comment to your question had I been able.

UPDATE: 22 August 2018
OK. Let's start this discussion again. You do need to add the taxonomy but that isn't the reason that your authors can't see/edit your posts.

In your function to register_post_type, there were some syntax errors in your "capabilities" that were enough to stop an author seeing the uo post. So, edit 'capabilities' to match the following:

'capabilities' => array( 'create_posts' => 'do_not_allow', // false < WP 4.5, credit @Ewout 'read_posts' => 'read_uos', 'edit_post' => 'edit_uo', 'edit_posts' => 'edit_uos', 'publish_posts' => 'publish_uos', 'edit_published_posts' => 'edit_published_uos', 'edit_others_posts' => 'edit_others_uos' ),

Using the Members plugin, assign all the capabilities for "uo Articles", though maybe you won't want to grant the various "delete" and "private" capabilities.

You don't need to add the additional author role. In fact, it might be more confusing that it is worth.

6
  • thank you for that! Still i am fairly new to wordpress. register_taxonomy is kind of a big chapter as i just found out. could you please share an example for this situation, cause i am quite lost. cheers
    – JoePanpi
    Commented Aug 19, 2018 at 15:35
  • Have a look at this post Add custom taxonomy to custom post type. It covers registering both a custom post_type and a taxonomy. The OP shows their complete code and the answer to their question involved only two minor typographical errors. Also note that the Codex advises using the "init" action to call register_taxonomy. In the example, the OP put it all in a plugin, which was a sensible approach.
    – Tedinoz
    Commented Aug 20, 2018 at 6:43
  • ok i will follow this example. but before i do this (cause i am totally afraid of breaking my settings ...:P)... i am trying to understand: my custom post type is working great so far. Admins and Editors can edit. My problem is that Authors can only "Preview". there is no "Edit". Why edit is working for Editors without registering the taxonomy and not for Authors?
    – JoePanpi
    Commented Aug 20, 2018 at 10:01
  • The taxonomy isn't the reason that your authors can't see/edit your posts. Edit 'capabilities' to match the following: 'capabilities' => array( 'create_posts' => 'do_not_allow', // false < WP 4.5, credit @Ewout 'read_posts' => 'read_uos', 'edit_post' => 'edit_uo', 'edit_posts' => 'edit_uos', 'publish_posts' => 'publish_uos', 'edit_published_posts' => 'edit_published_uos', 'edit_others_posts' => 'edit_others_uos' ), Assign all the capabilities for "uo Articles", though maybe you won't want to grant the various "delete" and "private" capabilities.
    – Tedinoz
    Commented Aug 21, 2018 at 9:08
  • Yes! that did the job! Thank you very much. i had misunderstood that naming a capability was free and not edit_, published_, etc. Can you paste your code in your answer above so i can mark it as the correct answer?
    – JoePanpi
    Commented Aug 21, 2018 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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