I am looking for a way to retrieve the default field keys and values. I am not looking to retrieve a field that has already been created/saved, instead I just want the default keys and values that are used when creating that field. Is there a way?
For instance the tab field, has these settings (see below)… I got this from the export tool, but is there a way to get them with a func/filter?
I was manually duplicating this in my code, but I figured it would be best to retrieve from the plugin, in case the plugin updates the field keys.
array ( 'key' => '', 'label' => '', 'name' => '', 'type' => 'tab', 'instructions' => '', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array ( 'width' => '', 'class' => '', 'id' => '', ), 'placement' => 'top', 'endpoint' => 0, ),
get_field_object() will do that https://www.advancedcustomfields.com/resources/get_field_object/
If you want to get information about a field that’s not created yet for a particular post, then you need to use get_field_object() using the field key.
The load_field filter can be used to get the information when a field is loaded https://www.advancedcustomfields.com/resources/acfload_field/
ACF will never rename a field key once it’s create. Unless Elliot decides to completely rework everything about the way ACF works.
I think we are talking about 2 different things, and it’s probably my fault. I’m working on a options page. All fields in the options page are created on the fly, so I wanted to get the default field keys per field type as defined in the plugin and then merge with the key/values I am using. I was try to access the class directly… but I failed to realize that the acf_add_local_field already does that for me.
Sorry. I am pretty terrible at describing things… the key fields are generated on the fly but based on a bunch of other information, so they will be unique but the same every time.
Anyway, no worries, because I was trying to merge my arrays with the default acf array, but that’s is already done by ACF when adding a field.
K, all makes sens to me know. I do the same thing. The only requirements for the field keys is that they are unique, don’t change and start with “field_” Generally I create field like “field_prefix000001”, “field_prefix000002”, etc. so I know they will never be the same as a key that ACF will ever create. Then like you said, you’re good to just use the ACF function to add field groups and fields.
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!
© 2022 Advanced Custom Fields.