Home Forums General Issues Working with dynamic field keys


Working with dynamic field keys

  • G’day

    I’m currently using ACF lite for custom theme development. To create feilds, ordinarily, I would build them using the ACF admin, export the array, then add that to the custom theme code. I’m at a point where I have a bunch of fields that I always use and have embedded them directly into my own little ‘framework’. This is all implemented through classes.

    I’m now needing the ability to extend certain field groups by extending their parent classes and modifying the field array. But, I’m unsure of the best approach when it comes to working with field keys. I have noticed that changing the key doesn’t seem to affect the data, but I’m sure the key is there for good reason, and so, I would prefer a more static approach to generating keys than just using random strings each time a page loads.

    One way that I have used recently, was to have the same key for a bunch of sub-fields, but just increment the last two digits of that key. This way works great so far, but if there is a smarter, more ACF-oriented approach, I would love to hear it.


  • Hi @mishtershmart

    The field key is a unique identifier for the field object. ACF uses this field key to link the value saved on a post back to the field object.

    ACF can’t use the field’s name, as there could be 2 or more fields with the same name.

    The field key must be unique and just not change on each page load (cannot be dynamically generated on the fly).


  • Hi @mishtershmart

    As for the sub field keys, as long as they are unique, then there is no issue here.


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

The topic ‘Working with dynamic field keys’ is closed to new replies.