Home Forums General Issues Use [\'parent\'] key to get the parent field object


Use [\'parent\'] key to get the parent field object

  • I’ve taken over a project and the previous developer seemed to be using the ['parent'] key of a subfield object to get the parent field object. This made sense, as the code expects the unique field key of the parent field was stored in the subfield’s ['parent'] key.

    however, it is not working and on inspection using var_dump of the subfield, the ['parent'] key actually returns the ['ID'] of the parent field (and the post ID of the Field Group if not a subfield).

    However, there seems to be no way to get a field object from it’s ID – get_field_object uses field key or name.

    Did this change at some point, where ['parent'] stopped holding the parent field key and instead the ID? Why? Especially if it means I now can’t get the parent field from it! What’s the point of it otherwise?

    If I have to totally rewrite his code and do what it’s doing in another way, OK, but would obviously rather just update what is there to work with ACF’s updated functionality. And still curious what the point of only storing the parent ID is if it can’t be used…

    If I’m missing something, I would appreciate any help. Like how to get a field object from just its ID…I can’t find any documentation for this.

    Thank you!

  • I don’t know when this changed or why, to be honest, I did not know until now that fields stored in the DB use the field/group ID here rather than the key. My suggest about getting an answer to why the change would be to submit a ticket here

    As far as fixing it how, you can use the ID if you use the function acf_get_field($selector)

  • The parent is not related… its the group. So u’ might mean making that cloned a group inside the element. But that’s a given and not the solution.

    Anyhow thanks. I guess there is no solution.
    acf should save the ref for the original field but I guess its
    an optimization issue or something.

    Maybe I would find a way to auto-tick that save as a group so as to at least have a better flow when working.

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

You must be logged in to reply to this topic.