Tell us what you are trying to do?
I used a great script from one of your team members to allow a custom post to be password protected and to pull the password from a form field. But I also wanted to see if there is a way to allow the post to be updated to "public" using an edit form so that the user can change their post between password-protected and public.
Is there any documentation that you are following?
https://toolset.com/forums/topic/password-protect-custom-posts-with-toolset-forms/#post-1452647
Is there a similar example that we can see?
What is the link to your site?
Hello,
You can setup a post form for editing post, option "Set this post status" choose "Published":
https://toolset.com/course-lesson/front-end-forms-for-editing-content/
So after user submit above edit post form, the post will be changed to "Published"
I am actually wondering about the "visibility" setting of the post, not the "status" of the post. I am using the script provided in the other forum post to set the visibility setting to "Password-protected" and to pull the password from a form field. At this point, I wanted to see about getting help in setting the visibility back to "public" using a form field.
There are 8 kinds of built-in post status within WordPress, see WP document:
https://wordpress.org/support/article/post-status/
If you setup a post as published then it will be viewable by everyone
https://wordpress.org/support/article/post-status/#publish
And it should be able to override "visibility" setting of the post
I set it up to publish, but in the post edit form, it is publishing a second version of the post rather than just updating the status of the current post.
Thanks for the details, I have tried it in my localhost, you need to remove the post_password after submit the edit post form, for example, add below codes into your theme file:
add_action('cred_save_data', 'remove_password_action',10,2);
function remove_password_action($post_id, $form_data)
{
// Change the ID below to the ID of your Toolset Form
if ($form_data['id']==123) {
$my_post = array(
'ID' => $post_id,
'post_password' => ''
);
// Insert the post into the database
wp_update_post( $my_post );
}
}
Please replace 123 with your edit post form's ID, and test again
That was perfect. Thank you for the help!