Home › Forums › General Issues › Password protect page with password being a custom field value › Reply To: Password protect page with password being a custom field value
Ya, missing something very important
add_filter('acf/save_post', 'post_password_from_acf', 20);
function post_password_from_acf($post_id) {
if (get_post_type($post_id) != 'your-post-type') {
return;
}
$password = get_field('your-acf-field', $post_id);
$post = get_post($post_id);
$post->post_password = $password;
remove_filter('acf/save_post', 'post_password_from_acf', 20);
wp_update_post($post);
add_filter('acf/save_post', 'post_password_from_acf', 20);
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.