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.
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
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.
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.