Home › Forums › General Issues › Automating Shortcodes to ACF conversion › Reply To: Automating Shortcodes to ACF conversion
Hi @tazintosh
Yes, the update_field()
function can add or replace the current flexible content value.
If you want to replace the value, you can use the code I gave you before.
If you want to add the value (if you have existing value), you can get the flexible content value first and add the new value like this:
// you need to get the post ID dynamically too
$post_id = 99;
// get the existing value first
$value = get_field('flexible_content_name', $post_id);
// add the value instead of replacing it
$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" ),
);
Also, please keep in mind that a clone field has a different structure based on the settings. Kindly check it first and adjust the value structure before updating it. You can check it like this:
$value = get_field('flexible_content_name', 99);
echo "<pre>";
print_r($value);
echo "</pre>";
I hope this helps 🙂
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.