ACF Fields Not Saving Values: Bug Breakdown and Solution
Have you ever used Advanced Custom Fields to create a bunch of custom fields for a page, filled them out, hit Publish or Update, only to find that a field or two appears blank? You thought you forgot the field, so you try again and it happens again. Every. Single. Time.
This happened to me again for the third time. One time it happened while staging for production. I had a tight deadline and the safest guarantee was to recreate the page and enter all that content back in. Thankfully, you don’t have to. It’s a simple a fix.
Field groups, the page where you edit the fields, are like any other post or page to WordPress. They’re added to the wp_posts table when you publish them.
When you add fields to a field group, they appear as meta for the field group, which you can find in the wp_postmeta table.
When you make a new post or page that uses these field groups, the meta data is created for the new page. If you update your field group later on, it’ll add whatever field is missing.
ACF only adds fields. I’m not sure if this is by design, but it is protective because your post meta doesn’t get deleted if you change a field name, it just creates a new one. Unfortunately, that means you’ll have to enter content in again if the field name changes. If you need the old value, just change the field name back.
If you look way above to the field group screenshot or the wp_postmeta table, you’ll see that the field name for State is capitalized. Field names are how we get the meta in our code, so we want to be consistent! If you change it to “state” from “State,” you will recreate the problem this post is about.
The problem: If your field name is the same, but the casing is different, ACF won’t recreate that field because it already exists. When you update the page using this field group, you’re saving into the abyss.
Just delete the fields associated with the page and update the field groups. You can find out the page ID by checking the address bar while on the page with the field groups. In the screenshot above, I’d delete row 22 and 23.
ACF will autofill the field name if you hit tab after filling out the field label, but if you really want to be cautious, you can create Advanced Custom Fields field groups with PHP! Edit (3/21): This is a PRO feature.
Did this help you out with your problems? Was this easy to follow? Let me know in the comments!