Home › Forums › Add-ons › Flexible Content Field › Flexible content array_splice help › Reply To: Flexible content array_splice help
The issue with getting a field in acf is that it returns an array using field_name => value
pairs and that you must use field_key
value pairs when you call update field to move copy it into a page, and this includes all sub fields.
In order to copy an layout you must loop over both the place you want to copy it from and the place you want to copy it to. I don’t know the exact details of what you are doing so I can only give the basics. This example will copy all of the flex rows from one post to another post.
// initialize rows to be updated
$rows = array();
// loop over the flex field on the post where you want to copy fields from
if (have_rows('flex_field', $post->id)) {
while (have_rows('flex_field', $post_id)) {
// the_row returns a value
// this value is an array of field_key => value pairs
// including any nested fields
$rows[] = the_row();
}
}
// then loop over the fields you want to copy to
// the same as above using a different post ID
// update the flex field on the post you want to update
update_field($field_key, $rows, $copy_to_post_id);
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.