Title: [BUG] Advanced Link Sub Fields
Last modified: February 9, 2023

---

# [BUG] Advanced Link Sub Fields

 *  Resolved [magic976](https://wordpress.org/support/users/magic976/)
 * (@magic976)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/bug-advanced-link-sub-fields/)
 * Hi, We recently upgraded from 0.8.8.10 to 0.8.9, and our Sub Fields in Advanced
   Link have stopped working.
 * When clicking Edit on a link, I can see the Sub fields I have added. On post 
   submit, the fields are saved. This can be verified on the Front end of the site
   and in the DB field. However once the Edit Page re-loads and you click to Edit
   the Link again, the Sub Fields will be empty. Updating the page at this point
   will erase those fields from the DB and Front end.
 * I saw in v0.8.8.11 there was some re-work done with this field. Is there a new
   way to add the filters for this? I didn’t see any change in the documentation.
 * Happy to provide more info if needed.
 * Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Konrad Chmielewski](https://wordpress.org/support/users/hwk-fr/)
 * (@hwk-fr)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/bug-advanced-link-sub-fields/#post-16457435)
 * Hello,
 * Thanks for the feedback!
 * I just tested it, and it works fine on my end. [Here is the video of my test](https://www.acf-extended.com/share/3oWWe)
   with a switch & repeater sub field.
 * Can you please share the code you’re using to register these sub fields (or at
   least part of them if there’s too many)? So I can try to reproduce the issue 
   on my side.
 * Here is the code I used, if you’re interested:
 *     ```wp-block-code
       add_filter('acfe/fields/advanced_link/sub_fields/name=my_advanced_link', 'my_acf_advanced_link_sub_fields', 10, 3);
       function my_acf_advanced_link_sub_fields($sub_fields, $field, $value){
   
           $sub_fields[] = array(
               'name'      => 'my_field',
               'key'       => 'my_field',
               'label'     => 'My field',
               'type'      => 'true_false',
               'ui'        => true
           );
   
           $sub_fields[] = array(
               'key' => 'repeater',
               'label' => 'Repeater',
               'name' => 'repeater',
               'aria-label' => '',
               'type' => 'repeater',
               'instructions' => '',
               'required' => 0,
               'conditional_logic' => 0,
               'wrapper' => array(
                   'width' => '',
                   'class' => '',
                   'id' => '',
               ),
               'layout' => 'row',
               'pagination' => 0,
               'min' => 0,
               'max' => 0,
               'collapsed' => '',
               'button_label' => 'Add Row',
               'rows_per_page' => 20,
               'sub_fields' => array(
                   array(
                       'key' => 'sub_field',
                       'label' => 'Sub Field',
                       'name' => 'sub_field',
                       'aria-label' => '',
                       'type' => 'text',
                       'instructions' => '',
                       'required' => 0,
                       'conditional_logic' => 0,
                       'wrapper' => array(
                           'width' => '',
                           'class' => '',
                           'id' => '',
                       ),
                       'default_value' => '',
                       'maxlength' => '',
                       'placeholder' => '',
                       'prepend' => '',
                       'append' => '',
                       'parent_repeater' => 'field_63e57b78406a0',
                   ),
               ),
           );
   
           return $sub_fields;
   
       }
       ```
   
 * Thanks in advance!
 * Regards.
 *  Thread Starter [magic976](https://wordpress.org/support/users/magic976/)
 * (@magic976)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/bug-advanced-link-sub-fields/#post-16459384)
 * Looking at your video, two things stand out. It looks like you might be using
   the classic editor? We are using the Gutenberg editor. And then did you give 
   the page a hard refresh once updated?
 * Here is our code we use:
 *     ```wp-block-code
       add_filter( 'acfe/fields/advanced_link/sub_fields', array( RegisterAcf::class, 'add_advanced_link_fields' ), 10, 3 );
   
       ------
   
       public static function add_advanced_link_fields( $sub_fields, $field, $value ) {
       	$sub_fields = array_merge(
       		$sub_fields,
       		array(
       			array(
       				'name'         => 'tn_element',
       				'label'        => 'Turnstile Element Name',
       				'type'         => 'text',
       				'instructions' => 'Add a name here to show as the data-tn-element.',
       			),
       			array(
       				'name'      => 'aria_label',
       				'label'     => 'Aria Label',
       				'type'      => 'text',
       				'instructions' => 'Please provide a descriptive Aria Label.',
       			),
       		),
       	);
   
       	return $sub_fields;
       }
       ```
   
 * Thanks!
 *  Plugin Author [Konrad Chmielewski](https://wordpress.org/support/users/hwk-fr/)
 * (@hwk-fr)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/bug-advanced-link-sub-fields/#post-16460810)
 * Hello,
 * Thanks for the details!
 * I can confirm that it also works on Gutenberg and after a refresh.
 * However, I see that you’re missing `key` arguments in your sub fields declaration,
   this is what is causing the issue.
 * Adding a `key` in all sub fields will fix the issue. Usage example:
 *     ```wp-block-code
       public static function add_advanced_link_fields( $sub_fields, $field, $value ) {
           $sub_fields = array_merge(
               $sub_fields,
               array(
                   array(
                       'name'  => 'tn_element',
                       'key'   => 'tn_element',
                       'label' => 'Turnstile Element Name',
                       'type'  => 'text',
                   ),
                   array(
                       'name'  => 'aria_label',
                       'key'   => 'aria_label',
                       'label' => 'Aria Label',
                       'type'  => 'text',
                   ),
               )
           );
   
           return $sub_fields;
       }
       ```
   
 * I think it’s an oversight from the rework of the Advanced Link field in 0.8.9.
   Previously, a subfield with a missing `key` would have its key generated using
   its `name`.
 * However, the rework considerably enhanced the field logic, to make it compatible
   with more complex subfields such as Repeater/Flexible Content, which wasn’t possible
   with the previous logic. The old “generate key when missing” code was part of
   the logic which made Repeater/Flexible Content incompatible back then.
 * I’ll add a safeguard in the next update in order to handle the scenario where
   subfields keys are missing, just in case.
 * However, note that it is considered good practice to provide a field `key` whenever
   you’re declaring a field (in ACF or ACFE). It’s always better to provide it, 
   so you can have full control on it.
 * Hope it helps!
 * Have a nice day!
 * Regards.
 *  Thread Starter [magic976](https://wordpress.org/support/users/magic976/)
 * (@magic976)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/bug-advanced-link-sub-fields/#post-16466323)
 * That worked! Thank you so much for your quick responses and continued work on
   the awesome package!
 *  Plugin Author [Konrad Chmielewski](https://wordpress.org/support/users/hwk-fr/)
 * (@hwk-fr)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/bug-advanced-link-sub-fields/#post-16467879)
 * Hello,
 * I’m glad to hear it now works as expected!
 * Have a nice day!
 * Regards.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘[BUG] Advanced Link Sub Fields’ is closed to new replies.

 * ![](https://ps.w.org/acf-extended/assets/icon-256x256.png?rev=2071550)
 * [Advanced Custom Fields: Extended](https://wordpress.org/plugins/acf-extended/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/acf-extended/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/acf-extended/)
 * [Active Topics](https://wordpress.org/support/plugin/acf-extended/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/acf-extended/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/acf-extended/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Konrad Chmielewski](https://wordpress.org/support/users/hwk-fr/)
 * Last activity: [3 years, 3 months ago](https://wordpress.org/support/topic/bug-advanced-link-sub-fields/#post-16467879)
 * Status: resolved