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>";
    echo "</pre>";

    I hope this helps 🙂