Skip Navigation

[Resolved] Custom role being set as author

This support ticket is created 4 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by matthewL-7 4 years ago.

Assisted by: Raja Mohammed.

Author
Posts
#1841505

Hi

I want to be able to set a custom role as the author on my CPTs so they can then edit them in the front end.

I follow the advice here: https://toolset.com/forums/topic/cant-add-new-user-with-new-custom-role-as-author/

But this then only shows this custom role as possible authors when I want to be able to set admins, editors still as well. Any ideas?

Thanks

#1842083

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello there

In the code mentioned in the referred ticket, You can specify multiple roles as an array of roles by replacing $query_args['role'] with $query_args['role__in']

 $query_args['role__in'] = array( 'contributor', 'administrator' );

the final code would be like

function wpdocs_add_members_to_dropdown( $query_args, $r ) {
    // Add multiple roles
    $query_args['role__in'] = array('member','editor','administrator');
   
    // Unset the 'who' as this defaults to the 'author' role
    unset( $query_args['who'] );
   
    return $query_args;
}
add_filter( 'wp_dropdown_users_args', 'wpdocs_add_members_to_dropdown', 10, 2 );

Reference : https://developer.wordpress.org/reference/hooks/wp_dropdown_users_args/#comment-4087

I hope that helps.

Regards
Raja

#1843287

I did actually try this but I added a space between the arrays! I was guessing I don't know much about PHP.

Thanks for your help. I should have double checked my work on Google.