After an upgrade I see duplicate fields in some of our field groups. I’ve tracked it down to there being duplicate fields before the upgrade that don’t show up in the ACF UI.
For example, before upgrading I can see this in the db for one of the duplicated fields.
| meta_id | post_id | meta_key |
| 5440 | 4 | field_53cd8928a638a |
| 8218 | 4 | field_53cd8928a638a |
| 9108 | 4 | field_53cd8928a638a |
| 26411 | 4 | field_53cd8928a638a |
| 26432 | 4 | field_53cd8928a638a |
| 26453 | 4 | field_53cd8928a638a |
| 36255 | 4 | field_53cd8928a638a |
| 36276 | 4 | field_53cd8928a638a |
| 36297 | 4 | field_53cd8928a638a |
I suspect this happened when we were importing the field groups between systems. If the existing posts aren’t deleted before importing, duplicate meta data can be created.
I think ACF v4 handled this, while v5 is exposing it.
I was able to fix it by changing the query in advanced-custom-fields-pro/admin/updates/5.0.0.php
// get field from postmeta $rows = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d AND meta_key LIKE %s", $ofg->ID, 'field_%'), ARRAY_A);
change the “SELECT *” to “SELECT DISTINCT post_id,meta_key,meta_value”
First of all thank you very much for such an amazing plugin.
I have a pretty large website that we need updating to v5.
Have just performed the update in one of my “dummy” stage copies of the site and some field groups end up with crazy duplicates (some fields duplicated up to 5-6 times).
Same issue as the guys above I believe.
Is there any way to avoid this at all?
We need to perform the update as v5 has many features we would love to make use of however we can’t really afford to be cleaning up data dups etc..
Thank you for your attention
You must be logged in to reply to this topic.
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!
Sorry for the issues with ACF's API SSL certificate this morning. We've resolved it and your activations and downloads should be back to normal again. Thanks! ^LG— Advanced Custom Fields (@wp_acf) November 2, 2022
© 2022 Advanced Custom Fields.