Support

Account

Home Forums Bug Reports acf-field-functions.php:349 – Undefined index: key

Solving

acf-field-functions.php:349 – Undefined index: key

  • After updating from 5.7.10 to 5.8.0, I get the follow notice:

    Notice: Undefined index: key in /plugins/advanced-custom-fields-pro/includes/acf-field-functions.php on line 349

    It doesn’t seem to cause any issues other than throwing the notice. Any insight on how to resolve this?

    ACF Pro version: 5.8.0
    PHP version: 7.1.20
    ACF Implementation: Flexible content component using cloned ACF field groups as layouts.

    Thanks!

  • I didn’t update to 5.7.11 because of the issues outlined in the following thread: (Update 5.7.11 Crashes Site) https://support.advancedcustomfields.com/forums/topic/update-5-7-11-crashes-site/

    The site no longer crashes, but the Notice is still an issue.

  • Same here:

    Notice: Undefined index: key in .../acf-field-functions.php on line 349

    I switched off the WP_DEBUG_DISPLAY for now.

  • I opened a support ticket and got a response from the ACF team stating that they could not recreate the issue. At this point, I’ve just turned debug logging off as well.

  • Thanks for the info.

    I’ve got over 60 field groups, some of them are flexible fields with several of the other field groups as clones inside their flexible field layouts.

    Notices started to pop up after I’ve duplicated the field groups via WPML (WordPress Multilingual Plugin) functionality to make the field groups available in other languages.

    I did not consider the hierarchy of the fields while duplicating them. Meaning: I should have duplicated the ones which are used as clones first. And only after duplicating all the basic field groups I should have started with duplicating the rather complex ones.

    –> Might be the reason why I get these notices now.

  • The line that’s causing your issue indicates that the field group does not have a key, which should be impossible.

    As far as the duplicated groups for wpml and clone field. I don’t know how this works, but it could be that the duplicated groups that include cloned groups the key of the cloned group was not set correctly. I would try to edit these duplicated groups and check the clone field, maybe updating these will work?

  • Hi John,

    Thanks for your answer. Updating the fields didn’t help, so I went full circle:

    When I ditched the database and kinda “started from scratch” concerning the db (synchronizing all fields from the json files), the errors did not occur again.

    So I’m guessing: Might have been a minor glitch which might have nested itself in the db when I duplicated the fields into another language.
    –> Somewhere there/towards your assumption:

    it could be that the duplicated groups that include cloned groups the key of the cloned group was not set correctly

    Concerning this bug report: I’m good. I don’t think I’ll run into these notices again any time soon.

    Cheers

  • I am experiencing the same issue after upgrading from 5.7.10 to 5.8.0.

    Like the original author of this post, I use flexible layout fields, cloning other field groups in for each layout option.

  • Just adding the QueryMonitor debug output for reference (see attached). Happy to share additional details if helpful.

  • I had the same issue without using WPML or other plugins.
    The Problem was a field group (A) i used in another group (B) via clone.
    After deleting (A), the error occurs, because (B) was referencing a deleted field group. After deleting the cloned group from (B) the error disappears and everything was fine.

  • Hi,

    I have the same issue.
    I’m using a repeater of field group clones.
    In the “acf_get_fields” function, in line 356 of the acf-field-functions.php file (version 5.8.3), the parent value is an array of groups of fields, so they have no key or id.

    If you could add a presence check before calling $parent[‘key’] or $parent[‘id’] respectively to lines 349 and 356, this will resolve the notices.

    Thanks

  • Props to Pacart. –> Sounds like a plan!

  • I had this issue today and it took some time to debug.
    It turns out I accidentally deleted a field group, which was used for a cloned field someplace else. Reverting the deleted group, or deleting the cloned field, solved the issue.

  • I’m having this issue as well after updating 5.7.10 to the latest 5.8.7.

    Following Pacart’s advice I’ve added a presence check before calling $parent[‘key’] or $parent[‘id’] respectively and it seems to have solved the issue. Will the fix be included in any update soon?

  • I talked to ACF support to give them more details.
    Changes are ongoing and this should happen in one of the next updates.

  • I had this same issue after copying over a bunch of field groups over (via JSON) from one project to another. After reading this thread I realized that I probably missed a field group that was being cloned into another.

    I just removed the field that was trying to clone a field group that doesn’t exist. That cleared up the issue.

  • @edisonake is it possible for you to provide your (temporary) fix here?
    I tried to adopt this check but it seems not to work here.

  • @codaboor This is the file I changed in the plugin advanced-custom-fields-pro/includes/acf-field-functions.php

    ORIGINAL

    
    // Check local fields first.
    if( acf_have_local_fields($parent['key']) ) {
    	$raw_fields = acf_get_local_fields( $parent['key'] );
    	foreach( $raw_fields as $raw_field ) {
    		$fields[] = acf_get_field( $raw_field['key'] );
    	}
     	
    // Then check database.
    } else {
    	$raw_fields = acf_get_raw_fields( $parent['ID'] );
    	foreach( $raw_fields as $raw_field ) {
    		$fields[] = acf_get_field( $raw_field['ID'] );
    	}
    }
    

    MODIFIED

    
    if ( isset( $parent['key'] ) && isset( $parent['ID'] ) ) {
    
    	// Check local fields first.
    	if( acf_have_local_fields($parent['key']) ) {
    		$raw_fields = acf_get_local_fields( $parent['key'] );
    		foreach( $raw_fields as $raw_field ) {
    			$fields[] = acf_get_field( $raw_field['key'] );
    		}
    
    	// Then check database.
    	} else {
    		if ( isset( $parent['ID'] ) ) {
    			$raw_fields = acf_get_raw_fields( $parent['ID'] );
    			foreach ( $raw_fields as $raw_field ) {
    				$fields[] = acf_get_field( $raw_field['ID'] );
    			}
    		}
    	}
    }
    
  • @codaboor This is the file I changed in the plugin advanced-custom-fields-pro/includes/acf-field-functions.php

    ORIGINAL

    
    // Check local fields first.
    if( acf_have_local_fields($parent['key']) ) {
    	$raw_fields = acf_get_local_fields( $parent['key'] );
    	foreach( $raw_fields as $raw_field ) {
    		$fields[] = acf_get_field( $raw_field['key'] );
    	}
     	
    // Then check database.
    } else {
    	$raw_fields = acf_get_raw_fields( $parent['ID'] );
    	foreach( $raw_fields as $raw_field ) {
    		$fields[] = acf_get_field( $raw_field['ID'] );
    	}
    }
    

    MODIFIED

    
    if ( isset( $parent['key'] ) && isset( $parent['ID'] ) ) {
    
    	// Check local fields first.
    	if( acf_have_local_fields($parent['key']) ) {
    		$raw_fields = acf_get_local_fields( $parent['key'] );
    		foreach( $raw_fields as $raw_field ) {
    			$fields[] = acf_get_field( $raw_field['key'] );
    		}
    
    	// Then check database.
    	} else {
    		if ( isset( $parent['ID'] ) ) {
    			$raw_fields = acf_get_raw_fields( $parent['ID'] );
    			foreach ( $raw_fields as $raw_field ) {
    				$fields[] = acf_get_field( $raw_field['ID'] );
    			}
    		}
    	}
    }
    
  • @codaboor This is the file I changed in the plugin advanced-custom-fields-pro/includes/acf-field-functions.php

    ORIGINAL
    // Check local fields first.
    if( acf_have_local_fields($parent[‘key’]) ) {
    $raw_fields = acf_get_local_fields( $parent[‘key’] );
    foreach( $raw_fields as $raw_field ) {
    $fields[] = acf_get_field( $raw_field[‘key’] );
    }

    // Then check database.
    } else {
    $raw_fields = acf_get_raw_fields( $parent[‘ID’] );
    foreach( $raw_fields as $raw_field ) {
    $fields[] = acf_get_field( $raw_field[‘ID’] );
    }
    }

    MODIFIED
    if ( isset( $parent[‘key’] ) && isset( $parent[‘ID’] ) ) {

    // Check local fields first.
    if( acf_have_local_fields($parent[‘key’]) ) {
    $raw_fields = acf_get_local_fields( $parent[‘key’] );
    foreach( $raw_fields as $raw_field ) {
    $fields[] = acf_get_field( $raw_field[‘key’] );
    }

    // Then check database.
    } else {
    if ( isset( $parent[‘ID’] ) ) {
    $raw_fields = acf_get_raw_fields( $parent[‘ID’] );
    foreach ( $raw_fields as $raw_field ) {
    $fields[] = acf_get_field( $raw_field[‘ID’] );
    }
    }
    }
    }

  • @codaboor This is the file I changed in the plugin ‘advanced-custom-fields-pro/includes/acf-field-functions.php’

    ORIGINAL
    // Check local fields first.
    if( acf_have_local_fields($parent[‘key’]) ) {
    $raw_fields = acf_get_local_fields( $parent[‘key’] );
    foreach( $raw_fields as $raw_field ) {
    $fields[] = acf_get_field( $raw_field[‘key’] );
    }

    // Then check database.
    } else {
    $raw_fields = acf_get_raw_fields( $parent[‘ID’] );
    foreach( $raw_fields as $raw_field ) {
    $fields[] = acf_get_field( $raw_field[‘ID’] );
    }
    }

    MODIFIED
    if ( isset( $parent[‘key’] ) && isset( $parent[‘ID’] ) ) {

    // Check local fields first.
    if( acf_have_local_fields($parent[‘key’]) ) {
    $raw_fields = acf_get_local_fields( $parent[‘key’] );
    foreach( $raw_fields as $raw_field ) {
    $fields[] = acf_get_field( $raw_field[‘key’] );
    }

    // Then check database.
    } else {
    if ( isset( $parent[‘ID’] ) ) {
    $raw_fields = acf_get_raw_fields( $parent[‘ID’] );
    foreach ( $raw_fields as $raw_field ) {
    $fields[] = acf_get_field( $raw_field[‘ID’] );
    }
    }
    }
    }

  • This is the file I changed in the plugin ‘advanced-custom-fields-pro/includes/acf-field-functions.php’

    ORIGINAL
    // Check local fields first.
    if( acf_have_local_fields($parent[‘key’]) ) {
    $raw_fields = acf_get_local_fields( $parent[‘key’] );
    foreach( $raw_fields as $raw_field ) {
    $fields[] = acf_get_field( $raw_field[‘key’] );
    }

    // Then check database.
    } else {
    $raw_fields = acf_get_raw_fields( $parent[‘ID’] );
    foreach( $raw_fields as $raw_field ) {
    $fields[] = acf_get_field( $raw_field[‘ID’] );
    }
    }

    MODIFIED
    if ( isset( $parent[‘key’] ) && isset( $parent[‘ID’] ) ) {

    // Check local fields first.
    if( acf_have_local_fields($parent[‘key’]) ) {
    $raw_fields = acf_get_local_fields( $parent[‘key’] );
    foreach( $raw_fields as $raw_field ) {
    $fields[] = acf_get_field( $raw_field[‘key’] );
    }

    // Then check database.
    } else {
    if ( isset( $parent[‘ID’] ) ) {
    $raw_fields = acf_get_raw_fields( $parent[‘ID’] );
    foreach ( $raw_fields as $raw_field ) {
    $fields[] = acf_get_field( $raw_field[‘ID’] );
    }
    }
    }
    }

  • Adrian, This is the file I changed in the plugin ‘advanced-custom-fields-pro/includes/acf-field-functions.php’

    ORIGINAL
    // Check local fields first.
    if( acf_have_local_fields($parent[‘key’]) ) {
    $raw_fields = acf_get_local_fields( $parent[‘key’] );
    foreach( $raw_fields as $raw_field ) {
    $fields[] = acf_get_field( $raw_field[‘key’] );
    }

    // Then check database.
    } else {
    $raw_fields = acf_get_raw_fields( $parent[‘ID’] );
    foreach( $raw_fields as $raw_field ) {
    $fields[] = acf_get_field( $raw_field[‘ID’] );
    }
    }

    MODIFIED
    if ( isset( $parent[‘key’] ) && isset( $parent[‘ID’] ) ) {

    // Check local fields first.
    if( acf_have_local_fields($parent[‘key’]) ) {
    $raw_fields = acf_get_local_fields( $parent[‘key’] );
    foreach( $raw_fields as $raw_field ) {
    $fields[] = acf_get_field( $raw_field[‘key’] );
    }

    // Then check database.
    } else {
    if ( isset( $parent[‘ID’] ) ) {
    $raw_fields = acf_get_raw_fields( $parent[‘ID’] );
    foreach ( $raw_fields as $raw_field ) {
    $fields[] = acf_get_field( $raw_field[‘ID’] );
    }
    }
    }
    }

  • Seems it solves the problem.
    I hope it will be applied in the next release.

  • I’ve just come in to report that I have the exact same issue.
    I just exported fields from a local environment to the live site, then exported the live database to the local. And this happened. I doubled checked to see if all fields were exported correctly and they were. It’s happened I noticed on repeater fields.

Viewing 25 posts - 1 through 25 (of 27 total)

The topic ‘acf-field-functions.php:349 – Undefined index: key’ is closed to new replies.