Home Forums Bug Reports issues related to field key references Reply To: issues related to field key references

  • Elliot,

    thanks for the response.

    This is a custom plugin that accepts data over the XMLRPC protocol. it’s important because we’re not using the WP back-end (via /wp-admin/edit.php?…) to add data but basically a batch processor.

    we’re importing values to fields that have been already defined via the ACF administrative back-end.

    with the importer plugin, the wp_insert_post() function is used to actually create the post and then return the newly created post ID.

    once the post ID has been returned, the update_field() function is called for each of the ACF field values within the data package to associate the values to the field names for that post ID.

    the problem we have been experiencing is that the field reference (originally) was NOT being created for newly created posts.

    at that point I used the work-around referenced in my original post to set the field reference manually.

    the problem as I see it currently is that these steps do not associate the field key values that are assigned at the time of definition to the field names.

    even the get_field_reference() function provided by ACF doesn’t return the ‘field_<some-hash-number-here>’ field keys, but basically returns ‘field_<field_name>’. The problem with this is that the field_name doesn’t start with ‘field_’ and there is a disconnect.

    I wrote a wrapper to the update_field() function which attempts to get the field key using get_field_reference() and if it returns ‘field_<field_name>’ then it fiddles it and uses update_post_meta() to assign the actual field_name to the reference key. (e.g. if the field name is ‘acf_name’ , get_field_reference() would return ‘field_acf_name’ and set ‘_acf_name’ to ‘field_acf_name’ which doesn’t match ‘acf_name’)

    what this did was set two meta_key values in the postmeta tables:

    meta_key = ‘acf_name’, meta_value = ‘my name here’
    meta_key = ‘_acf_name’, meta_value = ‘field_acf_name’

    the modifications I made in the wrapper provided the following results:

    meta_key = ‘acf_name’, meta_value = ‘my name here’
    meta_key = ‘_acf_name’, meta_value = ‘acf_name’

    in WP 3.5 this workaround seemed to work without issues. the ACF provided get_field_object() would also properly map ‘_acf_name’ to ‘acf_name’ and retrieve the values within the object.

    after the upgrade to WP 3.7.1, we have specifically seen with radio button type fields that get_field_object() prepends ‘field_’ to the value in the reference field so that a lookup of ‘_acf_name’ would not return ‘acf_name’ (as defined in the database) but ‘field_acf_name’ and thus not returning a proper object. (in this case, the [‘choices’] element was missing)

    My thoughts are that when the ACF fields are originally defined, they’re assigned field_key values like ‘field_<some-hash-number-here>’ which ultimately need to be matched up to the reference fields in each post. Couldn’t there be some way to look up the ‘master’ field_key value via a function?

    for what it’s worth, I know enough PHP to be dangerous and not much more; I don’t really fully understand the inner workings of wordpress and how all the hooks / filters work (or are supposed to work). I’m submitting this issue mostly because the issue only arises as a result of using our importer and not by means of using the WP back-end editing and thus our theme developers are unable to assist. it seems to me that some hook and/or filter related to the ACF plugin isn’t being executed when the wp_insert_post() function is called as opposed to when the update/publish button is clicked in the back end editor.

    hopefully this was useful information.