When registering a field via PHP you can set your own Group and Field keys, and this makes it nice to use later in code because you don’t have to track down a random key and use that.
But registering through PHP isn’t ideal because you have to know the format of all the options, whereas updating/modifying groups through the UI is easy and quick.
I see there is a way to view the group key and field keys in the Screen Options area, but you cannot modify them (the group key, “slug”, is a text input, but it reverts whatever you type in upon save).
This would be very handy.
Thanks for the feature request. I’ll bring this to the developer’s attention.
Just as a note, I can see at least one reason why this is not already a feature. Everything depends on this field key.
If Elliot gave people the ability to change the field key they would then expect that changing the key would also change all of the rows in the postmeta and options tables as well so that no data was lost.
While I don’t think that allowing the field keys to be changed would be difficult; searching, finding and updating all the references to the field key would be a major project, and depending on the size of the site and the amount of db queries needed, it could potentially fail before it was completed.
Well right now if you change a field name, you already have to resave everything in the database. So changing the key would be just the same. And, if you just required the field name to be globally unique then you wouldn’t need both a key and a name. That seems to make more sense to me anyways, as it can get confusing have two fields with the same name, but for different posts/post types, etc.
I don’t think that globally unique field names would be an asset for everyone. For example, I build fields with the same names purposefully so that I can use the same code to retrieve them. A field group on one post type may be 50% the same as another field group on another post type. Or I may have multiple layouts that are 90% the same. With the same name I can build functions for getting the values and use them rather than different coding for every group.
I did some testing. It is possible to change the field keys when editing the field group. This is what I did:
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!
© 2020 Advanced Custom Fields. Subscribe