Support

Account

Home Forums General Issues Automating Shortcodes to ACF conversion Reply To: Automating Shortcodes to ACF conversion

  • Hi @tazintosh

    Thank you very much for the detailed explanation.

    For something like that, you need to get the image data from the shortcode first. Because ACF needs the image ID to save the image field, you need to get it by processing the shortcode. I’m not sure how you process the shortcode, so could you please share the code?

    After you get the before and after image IDs, you can update the flexible content by using the update_field() function. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/update_field/. Based on your explanation, it should be something like this:

    // these are the before and after image IDs. You need to get it from the
    // shortcode
    $before_image = 99;
    $after_image = 100;
    
    // field_123456789abc is the flexible content field key
    $field_key = "field_123456789abc";
    
    // set the flexible content value
    $value = array(
    	array( "before_image_field" => $before_image, "after_image_field" => $after_image, "acf_fc_layout" => "before_layout" ),
    	array( "before_image_field" => $before_image, "after_image_field" => $after_image, "acf_fc_layout" => "after_layout" ),
    );
    
    // update it
    update_field( $field_key, $value, $post_id );

    I hope this makes sense 🙂