So I have a really complex ACF repeater / flexible content field (essentially a pagebuilder).
What I want to do is get a specific sub-sub-subfield value from one post (
$source_post) and insert it in the corresponding place in another post (
$target_post) programmatically. I have a map that points to the subfield, in array and string form, it looks like this:
$fieldmap_array = array(  => 0  => columns  => 1  => layout_content  => 0  => image ); $fieldmap_string = [columns][layout_content][image];
(It is parsed from a string that I acquire dynamically via an ajax call).
Now I can get the value of that subfield from the original post like this:
$source_repeater_field_content = get_field('repeater_field', $source_post_id); foreach ($fieldmap_array as $key) : $source_repeater_field_content = $repeater_field_content[$key]; endforeach;
At the end of this loop
$source_repeater_field_content will contain the value I am looking for.
What I want to do now is to insert that value in the corresponding place in the target post, so basically do this:
$target_repeater_field_content = get_field('repeater_field', $target_post_id); $target_repeater_field_content['columns']['layout_content']['image'] = $source_repeater_field_content; update_field('repeater_field', $target_repeater_field_content, $target_post_id);
However I can't just type in a string that selects this correct subfield, I need to be able to dynamically point to the correct key in the target field array via a
foreach loop or by some other means and I don't know how to do that.
I don't even know how to ask this question correctly :( I assume I can do it with array pointers somehow? Help?
(If you are curious about application, I want to add a button next to all image fields in this pagebuilder that automatically synchronizes the image between translations of a page (wpml). My client has a site in 5 languages and they complain that it is a lot of work to switch images for each language separately. Since this would be done AFTER the page itself is translated, it does not work to just sync the entire post content).