Home Forums Backend Issues (wp-admin) Get field key via script


Get field key via script

  • Hello,

    my question:

    I insert values for fields via script using update_field() after I created the posted via wp_insert_post.

    Afterwards I can not get the values of the fields using get_field(…) obviously because the field-key is wrong. Of course I could map the field_key by manualy reading it out of the admin-panel througn an array or something. But is there maybe a more automic way of doing this?

    Help appreciated

  • Remark: I can get the field values after I update the post manualy in the editor. But that’s not a good solution.

  • Hi @markus.freise

    Becuase ACF stores it’s field within the wp_postmeta as a serialized array, there is no real way of searching for the field via it’s field_name.

    Sorry, but this is unfortunately not possible with ACF at the moment.

  • I’ve also been looking for a way to get the key from a name. The best solution I’ve come up with is adding a function which does a switch/case on the field name and applies a filter to return the key. However, it does require that you manually code a case/return/break for each field (probably not practical if you’ve got more than a few dozen fields).

    Code here:

  • Alright. I’ll do it the copy and paste-way as mentioned in the docs. 🙂

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

The topic ‘Get field key via script’ is closed to new replies.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.