Home › Forums › General Issues › Get parent key instead of id
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 ['parent']
key.
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 get_field_object()
.
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'];
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.