Home › Forums › General Issues › Flexible Content – Notice: Undefined index: ID
I’ve been adding to the plugin ‘ACF Flexible Content Preview’.
I added code to be able to retrieve keys from nested fields. It works well but leaves and error in the WP Admin on page using/editing Custom Fields.
Error: Notice: Undefined index: ID in /wp-content/plugins/advanced-custom-fields-pro/includes/acf-field-functions.php on line 361
The function is:
<?php
/**
* Get all ACF flexible content field layout keys
*
* TODO: Add caching?
*
* @return array
*/
public function retrieve_flexible_keys() {
$keys = [];
$groups = acf_get_field_groups();
if ( empty( $groups ) ) {
return $keys;
}
foreach ( $groups as $group ) {
$fields = (array) acf_get_fields( $group );
if ( empty( $fields ) ) {
continue;
}
foreach ( $fields as $field ) {
if ( 'flexible_content' === $field['type'] ) {
// Flexible is recursive structure with sub_fields into layouts
foreach ( $field['layouts'] as $layout_field ) {
if ( ! empty( $keys [ $layout_field['key'] ] ) ) {
continue;
}
$keys[ $layout_field['key'] ] = $layout_field['name'];
$sub_fields = (array) acf_get_fields($layout_field);
foreach( $sub_fields as $sub_field ) {
if( 'flexible_content' === $sub_field['type'] ) {
foreach( $sub_field['layouts'] as $layout_sub_field ) {
if ( ! empty( $keys [ $layout_sub_field['key'] ] ) ) {
continue;
}
$keys[ $layout_sub_field['key'] ] = $layout_sub_field['name'];
}
}
}
}
}
}
}
return $keys;
}
?>
I think the problematic line is $sub_fields = (array) acf_get_fields($layout_field);
Help appreciated.
The topic ‘Flexible Content – Notice: Undefined index: ID’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.