Dear Sir/Madam,
All users register into my site will be assigned as subscribers, I have CRED form to let subscriber to apply an tour application and add the applicants.
From the backend, when the administrator edit the CPT application or applicant, there is no choice from the Author to select the subscriber. I understand subscriber has no post edit ability, how can I associate the CPT created by the record via the CRED?
Is it must to create custom role to all new register user. It doesn't help even we change the access to allow Subscriber to edit/delete the CPT application and applicant. Please help.
Best regards,
Kelvin.
Hi Kelvin,
Thank you for contacting us and I'd be happy to assist.
To include the "subscriber" role users in the list of author selector in the admin area, you can use the "wp_dropdown_users_args" filter:
https://developer.wordpress.org/reference/hooks/wp_dropdown_users_args/#user-contributed-notes
For example, to limit the author selection to "subscriber" and "administrator" roles:
function wpdocs_add_subscribers_to_dropdown( $query_args ) {
// Use this array to specify multiple roles to show in dropdown
$query_args['role__in'] = array( 'subscriber', '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_subscribers_to_dropdown' );
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
regards,
Waqar
Dear Waqar,
I added below code in functions.php but doesn't work. Will it be only applied to WP default page and post, my post is the Toolset Custom Post.
add_filter( 'wp_dropdown_users_args', 'add_subscribers_to_dropdown', 10, 2 );
function add_subscribers_to_dropdown( $query_args, $r ) {
$query_args['who'] = '';
return $query_args;
}
Thanks for writing back and the code that I shared, will work for Toolset custom post types too.
I don't see where you've added the name of roles that should be included in the author list, in your code snippet.
( specifically check the line# 5 from my code snippet: $query_args['role__in'] = array( 'subscriber', 'administrator' ); )
Can you please check the code snippet that I shared earlier and use it as it is?
Dear Waqar,
Yes, I add your script to functions.php but not work, so I research the code I got from somewhere.
It is strange that the code is working on my test website, but not on yours.
Can you please share temporary admin login details along with the link to the page where this author drop-down can be seen?
Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.
Thank you for sharing the access details.
I see multiple (3) functions added for the filter "wp_dropdown_users_args" in the theme's "functions.php" file.
( screenshot: hidden link )
Can you please remove the 2nd and 3rd code blocks shown in the screenshot and then check the author dropdown again?
Dear Waqar,
Oh, sorry for my mistake. Yes, you helped to solve the issue.
My issue is resolved now. Thank you!