On one WP installation I got the key (field_xxxxxx) under the parent key of a field object, and under another installation I got the WP Post ID of the field instead of the key.
Can I configure that? What could be the cause?
You need to give more detail? I don’t know what you are referring to.
Seems to be the same as described here: https://support.advancedcustomfields.com/forums/topic/use-parent-key-to-get-the-parent-field-object/
So, once using the ACF PHP functions to get a field object, via for example
get_field_object(), the returned array holds the post ID of the parent field under the
While on another WordPress installation, under the exact same function returns the ACF key of the parent instead of the post ID.
How do I make sure, that I always receive the key value and not the ID value?
I still don’t know the answer or why parent is an ID in one case and the field key in others. I have never run into this.
Please see the attached screenshot, which is a dump of
That does not tell my why it is an ID in this case but it is a field or group key in a different case.
The only think I can thing of in this that it’s a field key when loaded in JSON or created in PHP and a post ID when it is loaded from the DB.
I have looked and I don’t see any simple way to convert that ID into a Key.
You can try
$field_group = acf_get_field_group($id);
$key = $field_group['key'];