1

I have custom post types that I would like to make editable by several users. I created one custom post type using the Toolset plugin. wp_update_post only allows us to set single author:

$user_id = array();
$userIds = get_field("agency_to_author",$_POST['post_ID']); // Get Multiple User assing using acf field.
foreach ($userIds as $key => $value) {
     $user_id[] = $value['ID'];
}
if(!empty($user_id)){
     $arg = array(
         'ID' => $_POST['post_ID'],
         'post_author' => $user_id,
     );
     wp_update_post( $arg );    
}
0

Easy way: use this plugin https://wordpress.org/plugins/user-role-editor/

More complicated way: You can use functions.php to add all of the custom capabilities to a specific roles. But ofc you need a name of these capabilities.

This code is usefull if you want to add X same capabilities to X roles.

Add to functions.php

   function wphm_add_custom_capabilities_to_roles($roles, $capabilities) {
     foreach($roles as $the_role) {
       $role = get_role($the_role);
       foreach($capabilities as $capability) {
         $role -> add_cap($capability);
       }
     }
   }

  wphm_add_custom_capabilities_to_roles(
    array(  // these roles will recieve capabilities
      'custom_user_role_wphm_support',
      'administrator'
    ),
    array( // capabilities
      "read_wphm_custom",
      "read_private_wphm_custom",
      "edit_wphm_custom",
      "edit_others_wphm_custom",
      "edit_published_wphm_custom",
      "publish_wphm_custom",
      "delete_others_wphm_custom",
      "delete_private_wphm_custom",
      "delete_published_wphm_custom"
    )
  );

To remove a capability with this loop just modify a line $role -> add_cap($capability); to $role -> remove_cap($capability)

  • I want to assign multiple author on single custom post type is it possible with wp_update_post function or any other way? – Vishal Tanna Oct 12 '16 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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