Support

Account

Home Forums Backend Issues (wp-admin) Using acf_add_local_field() To Add Fields To User Form

Unread

Using acf_add_local_field() To Add Fields To User Form

  • Hi,

    I am trying to add a new field to the User form using acf_add_local_field() but it does not seem to be working. Can someone please help me check my code to figure out why? This is my first time doing this.

    I have already echo the $post_id, $videoId and $postTitle so I know they are working. The group key, title and location information have been copied from an export.

    // Create User Video Field
    function new_video_hook( $post_id ) {
    		// Get Video ID
    		$videoId = get_video_ID($post_id);
    		$postTitle = get_the_title($post_id);
    
    		if(function_exists('acf_add_local_field_group')) {
    			acf_add_local_field_group(array(
    				'key' => 'group_5f50fee38ca1b',
    				'title' => 'Additional User Fields',
    				'location' => array (
    					array (
    						array (
    							'param' => 'user_form',
    							'operator' => '==',
    							'value' => 'all',
    						),
    					),
    				),
    			));
    			acf_add_local_field(array(
    				'key'    => 'field_vimeovid_' . $videoId . $post_id,
    				'label'  => $postTitle . ' Video Progress',
    				'name'   => $videoId . '_video_progress',
    				'type'   => 'text',
    				'parent' => 'group_5f50fee38ca1b',
    			));	
    
    			// Update post status
    			wpse001_set_admin_notice(get_current_user_id(), 'New user custom field added.', 'success');
    		}
    }
    add_action('acf/save_post',  'new_video_hook', 20);

    Many thanks!

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.