Home Forums Backend Issues (wp-admin) ACF Update multiple fields and multiple posts Reply To: ACF Update multiple fields and multiple posts

  • I am trying to copy content from old flexible layouts to new flexible layouts. For example, I have two flexible layouts called image media and one called video media. They each have multiple fields such as gallery, title, description, etc. I created new a new media layouts within in the flexible content that I would like to copy all of this content over on several pages.

    I would like to:

    1. Add new layout rows
    2. Move the content of the old layouts to the new layouts on 67 pages.

    I have a successful PHP function that is however unreliable and I’m not sure if what I’m doing is the best way of doing what I need done. Here is a general summary of what I’m doing, I’m happy to post the full function if needed:

    1. Grab all the pages with the proper template name using global $wpdb and get_posts()
    2. Loop through the flexible content field and find the layout row for the old content and creating a new array for each page storing this data
    3. Passing the new data and new flexible layout name I want to add to a function I’ve created
    4. Using ACF update_field() to update 67 pages in the loop above
    5. I am then calling this function by using add_action( 'acf/init', 'update_acf_image_section' )

    The issue I’m having is that is sometimes creates duplicate layout rows and I’m not confident enough in this function to push to production. Any guidance would be greatly appreciated.