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 🙂
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.