Home Forums General Issues Creating theme fields – generating a key? Reply To: Creating theme fields – generating a key?

  • Hi Elliot,

    Thanks for the reply. I found it helpful and I am creating a series of classes now to build fields and field groups.

    I have run into an issue though:

    I have a base acfField class from which I extend the different types. I was using the uniqid() function in the constructor to generate the key IDs as you suggested, but they weren’t ‘sticking’. Every time I refresh the page, the key for any new acfField() object regenerates. This actually prevents the field from getting written to the database when saving a post with the field(s).

    Any suggestions on how to get around this? In reality I only need it in situations where 2 fields exist with the same key (the key is based on the name at the moment). So far my solution has been to manually add a incremented number to the key for situations where there is a clash, but tracking that manually could become really unwieldy, depending on the complexity of the setup. It also seems risky, in that problems could arise that are not immediately obvious.