You could look into Membership Plugins such as Paid Memberships Pro that set categories to private based on membership level.
Thank you @brett but I am really looking for a straight forward functions.php solution. A plugin is overkill for one category.
Hello srdriggers,
Took me a little bit, but I think this will work for you. I believe I got snagged on an infinite loop issue while I was working on your function. In theory, the status should change to Private when the user Publishes or Updates their post. Pre-existing posts in the “private” category just need to be updated and their status will also change. Just change the category, switcheroo, to whatever category you are targeting in the function.
Please give it a try and see if it works.
function post_saved_set_to_private ( $post_id ){
if ( ! wp_is_post_revision( $post_id ) ){
// unhook this function so it doesn't loop infinitely
remove_action('save_post', 'post_saved_set_to_private');
if ( in_category( 'switcheroo' )) {
// Update post
$my_post = array( 'ID' => $post_id, 'post_status' => 'private' );
// Update the post into the database
wp_update_post( $my_post );
}
// re-hook this function
add_action('save_post', 'post_saved_set_to_private');
}
}
add_action('save_post', 'post_saved_set_to_private');
Closing this one out. Thanks for all the help!