Support

Account

Home Forums Front-end Issues Post status as protected with ACF Field

Solving

Post status as protected with ACF Field

  • Is there an option or function to change the visibility as “protected” and define a password for the Post using ACF fields?

    Please help!

  • There is not option for this built into acf.

    You would need to create your own fields and then create an acf/save_post filter to update the post status and set the password.

    
    add_filter('acf/save_post', 'set_password_from_acf', 20);
    function set_password_from_acf($post_id) {
      $post = get_post($post_id);
      $post->post_password = get_field('pasword_field', $post_id);
      remove_filter('acf/save_post', 'set_password_from_acf', 20);
      wp_update_post($post);
      add_filter('acf/save_post', 'set_password_from_acf', 20);
    }
    
  • There are no words to thank you, very few times someone gave me a code that works, generally they give part of a code that is of no use to me since I am not a programmer. What you gave me was copy and paste and it works!

    I looked for this code all over the internet and there was nothing, I would have had no choice but to pay a programmer, I am Latino and it is for a personal project that still does not generate anything, I mean, you saved me …

    I’m going to leave good reviews all over the place, and let me know if there is any way I can collaborate with you, Jhon. Thank you very much genius!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.