Support

Account

Home Forums General Issues question about field keys

Solved

question about field keys

  • I have a question about field keys.

    I’m currently working on quite a large project, basically I’m using your plugin to build another plugin. In the end I plan on exporting the fields and registering them in the plugin start up.

    Anyway, I really need to have a repeating set of fields with conditional logic in these fields. I understand that this is on the to-do list and I’m not trying to push that issue. I understand the complexities involved so I figure this could be a while in the making and I’m looking at a creative way to work around it.

    What I have is one instance of all the fields I need created manually through the ACF interface and the beginning of the export looks something like:

    register_field_group(array (
    		'id' => 'acf_additional-fields',
    		'title' => 'Additional Fields',
    		'fields' => array (
    			array (
    				'key' => 'field_51eb5127e3480',
    				'label' => 'Field 1', ...

    Since I am going to put this into the plugin I thought, rather than add every instance of all of the fields manually in the ACF editor, I would write a PHP script that loops enough time to create all the field I need, renaming things as needed, for example changing “Field 1” to “Field 2” etc.

    The only thing I’m not sure about is the acf field “key”, can this be altered?

    An example would be to rename the key field_51eb5127e3480 to
    – field_51eb5127e3480_00
    – field_51eb5127e3480_01
    – field_51eb5127e3480_02
    – field_51eb5127e3480_03

    So the question is, would this work or is the field key something that needs to be left alone? If this will not work, is there any other way they can be altered? For instance can I generate my own unique id for this purpose?

    I’d really rather not do the tedious work of adding every field manually and this is something that I could easily automate if I can change the key values.

    Thanks for the time.

    • Elliot

    • July 23, 2013 at 3:34 pm

    Hi @hube2

    The field key can be anything you like as long as it is unique and it starts with ‘field_’.

    you can call it ‘field_my_textarea’

    Cheers
    E

  • Great, thanks for the reply. I’ll probably stick with slightly altering whatever was created as the key when the field was created. Easy enough to use a preg_match to grab the fields and then duplicate and alter.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.