Title: Setting role for all posts by default
Last modified: July 16, 2024

---

# Setting role for all posts by default

 *  Resolved [theotherdavid](https://wordpress.org/support/users/theotherdavid/)
 * (@theotherdavid)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/setting-role-for-all-posts-by-default/)
 * Hi there, I was wondering if it’s possible to have a certain role ticked by default
   so that every time you create a post it’s automatically ticked for content restrictions?
   
   Our client has a feed that pulls in posts so all the post will be automated.
 * Thank you!

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Support [Omar ElHawary](https://wordpress.org/support/users/omarelhawary/)
 * (@omarelhawary)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/setting-role-for-all-posts-by-default/#post-17895580)
 * Hi [@theotherdavid](https://wordpress.org/support/users/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.
 *     ```wp-block-code
       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,
 *  Thread Starter [theotherdavid](https://wordpress.org/support/users/theotherdavid/)
 * (@theotherdavid)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/setting-role-for-all-posts-by-default/#post-17897278)
 * Hi [@omarelhawary](https://wordpress.org/support/users/omarelhawary/) that’s 
   perfect and working as expected. Thank you so much.
 *  Thread Starter [theotherdavid](https://wordpress.org/support/users/theotherdavid/)
 * (@theotherdavid)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/setting-role-for-all-posts-by-default/#post-17900189)
 * [@omarelhawary](https://wordpress.org/support/users/omarelhawary/) actually, 
   is there a way so that it only applies to posts and not pages?
 * Thank you!
 *  Plugin Support [Omar ElHawary](https://wordpress.org/support/users/omarelhawary/)
 * (@omarelhawary)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/setting-role-for-all-posts-by-default/#post-17900515)
 * Hi [@theotherdavid](https://wordpress.org/support/users/theotherdavid/),
 * Please replace the code with that one below:
 *     ```wp-block-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') {        update_post_meta($post_ID, '_members_access_role', 'administrator'); // change 'administrator' to the default role you want to use    }}
       ```
   
 * Regards,
 *  Thread Starter [theotherdavid](https://wordpress.org/support/users/theotherdavid/)
 * (@theotherdavid)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/setting-role-for-all-posts-by-default/#post-17904299)
 * [@omarelhawary](https://wordpress.org/support/users/omarelhawary/) perfect, thank
   you so much!
 *  Thread Starter [theotherdavid](https://wordpress.org/support/users/theotherdavid/)
 * (@theotherdavid)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/setting-role-for-all-posts-by-default/#post-17904418)
 * 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!
 *  Plugin Support [Omar ElHawary](https://wordpress.org/support/users/omarelhawary/)
 * (@omarelhawary)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/setting-role-for-all-posts-by-default/#post-17907908)
 * Hi [@theotherdavid](https://wordpress.org/support/users/theotherdavid/),
 * Here’s the updated version of the code:
 *     ```wp-block-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');    }}
       ```
   
 *  Thread Starter [theotherdavid](https://wordpress.org/support/users/theotherdavid/)
 * (@theotherdavid)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/setting-role-for-all-posts-by-default/#post-17908641)
 * [@omarelhawary](https://wordpress.org/support/users/omarelhawary/) you legend!
   Thank you again – appreciate it.
 *  Plugin Support [Omar ElHawary](https://wordpress.org/support/users/omarelhawary/)
 * (@omarelhawary)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/setting-role-for-all-posts-by-default/#post-17910081)
 * [@theotherdavid](https://wordpress.org/support/users/theotherdavid/) You’re welcome!
   Have a great day!

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Setting role for all posts by default’ is closed to new replies.

 * ![](https://ps.w.org/members/assets/icon-256x256.png?rev=3508404)
 * [Members - Membership & User Role Editor Plugin](https://wordpress.org/plugins/members/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/members/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/members/)
 * [Active Topics](https://wordpress.org/support/plugin/members/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/members/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/members/reviews/)

 * 9 replies
 * 2 participants
 * Last reply from: [Omar ElHawary](https://wordpress.org/support/users/omarelhawary/)
 * Last activity: [1 year, 10 months ago](https://wordpress.org/support/topic/setting-role-for-all-posts-by-default/#post-17910081)
 * Status: resolved