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 );
}

Comments on this post

  1. clifgriffin said on November 14, 2018 at 4:35 pm

    Thank you thank you. I could not find this either.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Trackbacks and Pingbacks on this post

No trackbacks.

TrackBack URL