Skip Navigation

[Resolved] Author Dropdown in Quick Edit won’t show users with custom user role

This thread is resolved. Here is a description of the problem and solution.

Problem:
Add custom user roles to author quick edit dropdown.

Solution:

This can be done by adding the following code to your functions.php file

add_filter('wp_dropdown_users_args', 'assign_any_users_author_box_func', 10, 2);
function assign_any_users_author_box_func($query_args, $r){
    $query_arg['who'] = 'any';
    return $query_arg;
}

It should be noted that the user role must also have permissions for the post type that you want them to show up on.

This support ticket is created 2 years, 11 months 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 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 3 replies, has 2 voices.

Last updated by kaiD-2 2 years, 11 months ago.

Assisted by: Shane.

Author
Posts
#2451701

Tell us what you are trying to do?

I'm trying to change the author of CPTs. WP only let me choose between 'admin', 'editor' and 'author' but i need to see all users.
The arg [who] is deprecated due an WP update and dosen't work anymore. a rollback is no option for the site.
I used the following snippet in functions.php :
------------------------------------------------------------------------------------------------------------------------
// Show all users in 'author' drop down on editor
add_filter( 'wp_dropdown_users_args', function( $query_args, $r ) {
$query_args['who'] = '';
return $query_args;
}, 10, 2 );
------------------------------------------------------------------------------------------------------------------------

I also tried an other as you can see in the following snippet but it also won't work:
------------------------------------------------------------------------------------------------------------------------
function show_all_users_dropdown( $query_args, $r) {
$query_args['role__in'] = ['supplier'];
return $query_args;
}
add_filter('wp_dropdown_users_args', 'show_all_users_dropdown', 10, 2);
------------------------------------------------------------------------------------------------------------------------

And i also tried this one below:
------------------------------------------------------------------------------------------------------------------------
function func_author_dropdown_user_args( $query_args ) {

// Use this array to specify multiple roles to show in dropdown
$query_args['role__in'] = array('administrator' );

// Unset the 'who' as this defaults to the 'author' role
unset( $query_args['who'] );

return $query_args;
}
add_filter( 'wp_dropdown_users_args', 'func_author_dropdown_user_args' );
------------------------------------------------------------------------------------------------------------------------

Is there any documentation that you are following?
Many like these:
https://make.wordpress.org/core/2022/01/05/new-capability-queries-in-wordpress-5-9/
https://toolset.com/forums/topic/author-dropdown-only-shows-users-with-admin-role/
https://developer.wordpress.org/reference/functions/wp_dropdown_users/

I want to choose between all users no matter wich role the user has. Or to add the users with the custom role 'supplier' to the dropdown.
Thank you for your assistance.

#2451819

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kai,

Thanks for getting in touch.

I've tested this code below and it works when added to the functions.php file.

add_filter('wp_dropdown_users_args', 'assign_any_users_author_box_func', 10, 2);
function assign_any_users_author_box_func($query_args, $r){
    $query_arg['who'] = 'any';
    return $query_arg;
}

This returns all the user roles and adds it to the author dropdown.

Please let me know if it works for you.
Thanks,
Shane

#2452061

Hi Shane,

thank you for your fast reply.
I've tried the snippet and it works for regular WP-Posts. But it doesn't work for a Custom Post Type.

Am I missing something?

Thank you for your assistance.

#2452183

My issue is resolved now. Thank you!
The snippet worked out. I just had to change the access controls for the custom role to their Post Type.