Support

Account

Home Forums Bug Reports Export/import field groups makes image fields return ID instead of array

Solving

Export/import field groups makes image fields return ID instead of array

  • In ACF Pro, when exporting and then importing field groups, image fields that are set to return arrays will return image IDs until the return type is changed. They remain set to return arrays in the UI, but they return the ID when using get_field. To get it to return arrays again I need to change it to ID, save, then change back to array and save again. I don’t know if it happens every time, but it has happened many many times.

  • Forgot an important detail. When importing/exporting, if the image field is set to return an array it changes to return an ID. And if the image field is set to return an ID it changes to return an array. This literally just happened to me 30 seconds ago (latest version).

  • This one was being really stubborn. Changing the field return type wouldn’t affect anything. Anyways, what I did was export the group to JSON, change a few characters in the image field keys, then delete the group and reimport the edited JSON. Then it starts returning the correct return type. Hopefully this is a reliable fix because this issue is extremely annoying and frequently breaks features when importing field groups between environments.

  • I have never seen this happen when exporting/importing a field group to a site. Not being able to recreate the issue would make it very hard to help.

    My initial reaction is that it must be something else.

    What else are you doing you are importing the field group? Are you moving anything else? doing exports/imports of any other kind?

  • This is a pretty common problem for me, and it happens on many different WordPress installs. I’d say it’s been happening for about a year, but it’s probably more like 1.5 years since Covid has screwed up my sense of time. I’m usually exporting locally and importing to a dev server. I always first delete the field group on the dev server, then import the json from my local install. The imported image fields will then only return IDs instead of arrays. It doesn’t happen with all image fields though. For the affected fields, I need to change them to return ID, save, then change back to array, save, and then the problem is usually fixed.

    This last one was being extremely stubborn and wouldn’t fix when changing the return type, but it was a somewhat unique use case. It was a disabled field group that was included in another field group as a Clone field (seamless replace). I deleted both field groups and reimported many times, and changed the return type many times. No matter what the image field would only return an array, not an ID (in this case I wanted the ID returned, not array.) Eventually I tried what I talked about above and that fixed it (exporting json, changing characters in the field key, and importing the modified json). Luckily I wasn’t using any hard-coded field keys anywhere so it immediately started working correctly.

    By the way, I want to add that when this problem happens, it always reverses the output type. If it’s set to an array, it will return an ID. If it’s set to an ID it will return an array. It seems to me that somewhere in the import process the return types get mixed up. The admin UI still shows the correct return type though (the correct radio button is selected), it just returns the wrong value.

  • I’m curious, because I have never seen this. I have another question.

    Do yu have any acf/load_field filters in place that effect image fields? And are these filters common for you?

    The reason I as is that acf/load_field filters can affect the fields during export and import. Or I should say that I have run into an issue with these filters interfering with exports/imports in the past.

  • Oh interesting. Yep, I frequently use load_field filters, although I always use them with the /key=field_XXXXXX params. I can’t say for the previous times I’ve had the issue, but this last time with the clone field I mentioned, there were no filters on any of those image fields.

  • I know that a lot of the documentation for ACF still shows using the acf/load_field filter for changing fields. But almost all of the time an acf/prepare_field filter is the better choice. This is a newer hook that was added after most of the documentation was written.

    acf/load_field filters will be applied when exporting fields.

  • That’s really good to know, thanks!! I definitely don’t want these filters to be applied when exporting.

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

You must be logged in to reply to this topic.