Home Forums Add-ons Flexible Content Field Issues with add_rows and flexible content Reply To: Issues with add_rows and flexible content

  • Looking over the ACF add_row() code myself I can tell you that add_row() as it works now can definitely not be used to add a layout to a flexible content field.

    The value of a repeater fields meta value is the number of rows in the repeater. The value of a flex fields meta value is a serialized array of layout names. Since add_row() always updates the meta value to a count of rows it cannot function for adding a layout.

    It may work if there are 0 layouts, I did not investigate what happens with 0 rows when this line is called.

    return (int) acf_update_value( array( $value ), $post_id, $field );

    but, if there is a value then this line converts the array of field names to 1

    $i = (int) acf_get_metadata( $post_id, $field['name'] );

    this can be tested by

    echo (int) array('test');

    That means that if( !$i ) { is not executed

    and then $i is incremented and saved to the meta value

    // increase $i
    // update meta
    $result = acf_update_metadata( $post_id, $field['name'], $i );

    which overwrites the array for the flex field with an integer, destroying the needed array.