Home Forums Front-end Issues Auto / Pre Populate ACF fields with their corresponding User fields i.e. email


Auto / Pre Populate ACF fields with their corresponding User fields i.e. email

  • I have a form which has a ACF field group. It is for first name, last name, and email – among other fields. The first name, last and email, when they are updated, they update the user fields. Everything is working fine including checking if the email is already in use. What I would like is that the ACF fields be pre-populated with their WordPress user counterparts. So someone will already have an email because you have to have one in WordPress. When they go to update this registration form, I want it to be pre-populated with their wordpress email. Then they can change it like usual if they want or have it stay as is. Something like:

    This is my email field $emailField = $_POST[‘acf’][‘field_5ae7a967009de’];

    I can get the user email like so usually.

    $current_id = get_current_user_id();
    $current_email = get_the_author_meta(‘user_email’, $current_id);

    make the $emailField have the value of the User’s WordPress registration email ( $current_email )

    I am not sure where I would put this.

    Currently I am doing this and have functions and overrides for what I’m building. Please help me out and be specific. I didn’t find any documentation online for this. Here are some of the functions and overrides of the project so far:

    add_action('acf/save_post', 'my_acf_save_post', 1);
    add_shortcode('userupdate', 'zUpdate');
    add_filter('acf/validate_value/name=my_user_email', 'my_acf_validate_value', 10, 4);

    This is the form I am currently using that’s output. Maybe you add some code here to do what I want to do?

    	$current_id = get_current_user_id();
    	$user_id = 'user_' . $current_id;	
    	$options = array(
    	    'post_id' => $user_id,
    	    /* my field group grabs unit, home phone, and cell phone acf */
    	    'field_groups' => array('3307', ),
    	    'submit_value' => 'Update',
    	    'html_after_fields' => '<input type="hidden" name="acf[register]" value="true"/>',
    	$form = acf_form( $options );
    	return $form;	

    Thank you in advance. Last piece of the puzzle. Need email, first name, last name from WP user profile.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.