I don’t know the solution. Figured I’d post something because I recently looked at doing the same thing.
I was building my own code to do the importing from a CSV, the main reason for this is that most of the plugins available do not really understand how to import data for ACF (even if they say they do) especially for things like repeater fields. Or for that matter importing attachments.
Anyway, I dug through everything looking for something that got stored in the DB to tell WP that there was a gallery there. I went as far as going through the steps of creating a WP gallery in a post, exporting the DB at every step and comparing the exports for any differences and doing the same thing for my imported data. I could find no reason for the gallery shortcode to not be processed properly from my import.
No matter what I did I found that the only way to get WP to recognize the gallery was to open and save every post. Not a very good solution for the client that was importing 800+ products all with a gallery.
I finally gave up, but I’d also really like to understand what I’m missing to get this done because I’m sure I’ll revisit this in the future. I don’t think this is really an ACF issue though, I’m sure it’s something to do with WP and some bit of data I’m missing somewhere, somehow.
There is one thing that I did not try now that I think about it. For every field you create ACF creates 2 fields in the postmeta table when you add values to a post. the first is the field name you created, for example “my_gallery_field”. The second is a has a key of “_my_gallery_field” and this one’s value is the ACF “key” value for your field. I know that for repeater fields that all fields, including the ACF key references need to be inserted into the database to make them work. I will give this a shot the next time I’m working on my import script. Could be a while before I get to it though. But maybe something you can try.
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!
© 2022 Advanced Custom Fields.