Home Forums Feature Requests Edit Group and Field Keys


Edit Group and Field Keys

    • emrl

    • April 24, 2015 at 5:24 am

    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.

    Thank you.

  • 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.


    • emrl

    • June 23, 2015 at 3:15 am

    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:

    • Examined the code in firebug.
    • before each field there are hidden fields in a wrapper div with a class of “meta”
    • if you remove the class name from this field you can then edit the field key in the hidden field and when you save the field group the field key will be updated to what you entered.

    I don’t know why this works, didn’t did that far. But given this it should be possible to create some custom JavaScript to remove the class from the wrapper, change the hidden field key field into a text field. Then you can change it and remove the JS when dev is done.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.