Hi @theotherdavid,
Thanks for reaching out Members Support Team!
Please copy/paste below PHP snippet to theme functions.php file and let me know if it helps.
add_action('save_post', 'update_members_access_role_after_publish');
function update_members_access_role_after_publish($post_ID) {
update_post_meta($post_ID, '_members_access_role', 'administrator'); //change administrator to default role you want to use
}
Regards,
Hi @omarelhawary that’s perfect and working as expected. Thank you so much.
@omarelhawary actually, is there a way so that it only applies to posts and not pages?
Thank you!
Hi @theotherdavid,
Please replace the code with that one below:
add_action('save_post', 'update_members_access_role_after_publish');
function update_members_access_role_after_publish($post_ID) {
// Check if the post type is 'post'
if (get_post_type($post_ID) === 'post') {
update_post_meta($post_ID, '_members_access_role', 'administrator'); // change 'administrator' to the default role you want to use
}
}
Regards,
@omarelhawary perfect, thank you so much!
Sorry I made a mistake and need it to be two roles by default. I’ve tried a bunch of code and ChatGPT couldn’t even help. Is there a way to do this? Thank you so much!
Hi @theotherdavid,
Here’s the updated version of the code:
add_action('save_post', 'update_members_access_role_after_publish');
function update_members_access_role_after_publish($post_ID) {
// Check if the post type is 'post'
if (get_post_type($post_ID) === 'post') {
add_post_meta($post_ID, '_members_access_role', 'administrator');
add_post_meta($post_ID, '_members_access_role', 'author');
add_post_meta($post_ID, '_members_access_role', 'editor');
}
}
@omarelhawary you legend! Thank you again – appreciate it.
@theotherdavid You’re welcome! Have a great day!