Home › Forums › Bug Reports › Bug: acf_get_reference() is returning incorrect field reference › Reply To: Bug: acf_get_reference() is returning incorrect field reference
There is not a way to get the field keys programmatically by the field name if they do not already exist. At least not easily.
There is a round-a-bout way to do this. There is a function in ACF, acf_get_field_groups(). This function takes arguments. I don’t remember the specifics, but the last time I looked at it I was able to get field groups based on the post ID. You can then loop over the field groups and get the fields in each groups using the function acf_get_fields(). Then you could loop over all of the fields and find the field name and get its key.
When working with repeaters you must use keys for the repeater and all of its sub fields.
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.