Home Forums General Issues Read & Understood toggle for logged in users Reply To: Read & Understood toggle for logged in users

  • First, this would not be saved as a single ACF field. The user IDs for the people that have toggled the “Read & Understood” field would be save into a standard WP custom meta field that allows multiple values. The ACF true/false field would simply be a mechanism to set values in this other field.

    From here your would create an acf/prepare_field filter for the true false field. This filter would look at the array of user IDs stored in the WP meta field to see if this user is present. If it is then set the value to 1 (true) if not then set the value to 0 (false). ACF will save this field to the post, but we really don’t care what it saves because the actual value will be determined by the values stored elsewhere.

    The next step is to create an acf/save_post action with a priority of < 10. We want this to run before ACF saves the value and we want to look at $_POST[‘acf’][$field_key]. The reason we want to look here is because this is the submitted value and will be unaffected if 2 people happen to submit the form at exactly the same time. If we did this on the saved value we’d get whatever the last person submitted, which would be fine as long as you can guarantee 2 people can’t submit the form at the same time, which would be nearly impossible.

    In this acf/save_post action you would get the submitted value. If it is “1” then you would add this user ID to the WP meta field if they are not already present. If it is “0” then you would remove them from the list if they exist.