Support

Account

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

  • This can be accomplished the same way that any WP post field can be changed based on an acf field.

    
    add_filter('acf/save_post', 'post_password_from_acf', 20);
    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);
    }