Support

Account

Home Forums Backend Issues (wp-admin) [q] Is it possible to add fields automatically after adding in other group? Reply To: [q] Is it possible to add fields automatically after adding in other group?

  • Hi @razider

    I believe you can use the acf/update_field_group and acf_update_field() function to do that. Here’s a simple example you can try:

    add_action('acf/update_field_group', 'my_acf_add_custom_field');
    function my_acf_add_custom_field($field_group){
        
        // set ID of field groups you want to update
        $field_group_ids = array(4002);
        
        // loop through the IDs
        foreach( $field_group_ids as $field_group_id ){
            
            // set the new field data
            $field = array(
                'key' => 'field_1',
                'label' => 'Sub Title',
                'name' => 'sub_title',
                'type' => 'text',
                'parent' => $field_group_id
            );
            
            // add the field
            $field_id = acf_update_field($field);
            
        }
        
    }

    I hope this helps 🙂