Update Group Fields ACF

In this case, I was trying to create a post and update the fields in an ACF group via WordPress’s wp_insert_post and the documentation on the ACF site ended up being incomplete on this.

function make_member_post(){
//THE WordPress PART
	$user = get_user_by( 'email', 'some_email@email.com' );
	$user_id = $user->ID;
	$args = array(
	    'author'        =>  $user_id,
		'post_type' => 'member', 
		'post_status' => 'publish',
		'post_title' => 'does not matter',  
    );
    $new_memmber = wp_insert_post($args);   

//THE ACF PART
	$field_key = 'THIS_WILL_BE_FROM_ACF_FOR_YOUR_GROUP';
	$values = array(
		'first_name'	=>	'joe',//THE 1st PART MATCHES YOUR FIELD NAMES, THE 2nd IS THE VALUE YOU WANT
		'last_name'	=>	'smith',
	);
	update_field( $field_key, $values, $new_memmber );
}

One thought on “Update Group Fields ACF

Comments are closed.