I’m try to load content into a flexible content field on an acf_form. Using the ‘acf/load_field’ filter, I can duplicate the rows and types. However, the content is not loading into the rows. Here is the current code:
function copy_flex( $field ) {
$post_id = isset( $_REQUEST['post_id'] ) ? $_GET['post_id'] : '';
$resources = get_post_meta( $post_id, 'resources', true);
if ( $resources ) {
$value = array();
foreach( $resources as $i => $resource ) {
$acf_fc_layout = $resource;
$label = get_post_meta( $post_id, 'resources_' . $i . '_label', true );
$url = get_post_meta( $post_id, 'resources_' . $i . '_url', true );
if ( $acf_fc_layout == 'link' ) {
$value[] = array(
'acf_fc_layout' => $acf_fc_layout,
'field_56e8dc9848480' => array(
'label' => $label,
'url' => $url
)
);
}
}
$field['value'] = $value;
}
return $field;
}
add_filter('acf/load_field', __NAMESPACE__ . '\\copy_flex');
Can someone help? Thanks!
Figured it out. Each of the items in the value array needed the corresponding field key rather than the field name:
$value[] = array(
'acf_fc_layout' => $acf_fc_layout,
'subfield_key_1' => $label,
'subfield_key_2' => $url
);
Can you please share the ultimate code?
This reply has been marked as private.
Hi,
Do you have an example of this I could reference?