AdvancedCustomFields / AdvancedCustomFields/acf
Loss of Repeater Field Data when Rearranging Layouts in Flexible Content
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
When using a Flexible Content field in ACF, which contains layouts that include Repeater fields, there is an issue where changing the order of the layouts in the WordPress admin interface results in the loss of data from the Repeater field within those layouts.
To Reproduce
Create a Flexible Content field in ACF and add layouts that contain Repeater fields.
Populate data in the Repeater fields within the layouts.
In the WordPress admin interface, rearrange the order of the layouts within the Flexible Content field.
Save the changes.
Notice that the data in the Repeater fields has been erased.
Expected behavior
Expectations: We expect that rearranging the layouts within the Flexible Content field should not result in data loss within the Repeater fields.
Statement
I wanted to provide an update regarding the configuration change I made in PHP. As recommended in the discussion thread found here: Thread Link, I adjusted the max_input_vars to 10000.
Unfortunately, despite making this adjustment, the issue of data loss when updating Flexible Content fields persists. The rows continue to disappear in the backend as mentioned in the thread.
Screenshots or Video
https://github.com/AdvancedCustomFields/acf/assets/33683465/def1c566-4254-410a-b5ce-08cd6d600431
Version Information:
- Web Server: Apache/2.4.54 (Unix) OpenSSL/1.0.2u PHP/8.2.0
- PHP Version: 8.2.0
- max_input_vars 10000
- MySQL Server Version: 5.7.39
- WordPress Version: 6.3.1
- ACF Version: 6.2.1.1
- Browser all
Additional informations
I've dug around in the ACF Pro code. It seems that this only happens when ACF fields are added directly via PHP code.
The problem lies in the update_value function in /pro/fields/class-acf-field-repeater.php
In fact, the variable $old_rows = acf_get_value( $post_id, $field ); is empty, because ACF fetches the value of the field being updated to perform operations ( row updated, row deleted ... ) with the new Layout index in LayoutContent, but this index doesn't yet exist in the database.
ACF should fetch the values in the current LayoutContent index for the old values.
Temporary Fix
What I did to correct this problem was to modify this code:
// Update any existing rows that were edited.
foreach ( $edited_rows as $key => $row ) {
if ( array_key_exists( $key, $old_rows ) ) {
$old_rows[ $key ] = $row;
}
}
To:
// Update any existing rows that were edited.
foreach ( $edited_rows as $key => $row ) {
//if ( array_key_exists( $key, $old_rows ) ) {
$old_rows[ $key ] = $row;
//}
}
Additional context
Thank you for considering this bug report and working towards its resolution. If additional information is required, please feel free to request it.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in /pro/fields/class-acf-field-repeater.php, especially update_value(), and reproduce the loss by rearranging PHP-defined Flexible Content layouts containing Repeater fields. Trace how $old_rows is loaded for the current layout index and compare it with the submitted edited rows; done means saving a rearranged layout preserves all existing Repeater data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100