Fixed: Creating a gallery programatically
-
EDIT: after a bit of tweaking, and trying something I’m sure I tried before, the following worked (‘gallery’ is the name of my Galerie 4 field in ACF)
update_post_meta($post_id,'gallery', $image_array);Hi, I am using some code to migrate a website, taking the content of static html pages to create postsMy wish is to add all images and automatically create a gallery on each post. I have successfully migrated the images and am at the point where I have the post ID and a simple indexed array of image IDs.
I have tried
update_field('field_6976a8648a5b', $image_ids, $post_id);and also tested replicating the postmeta value in the format I can see is stored in the database for a manually created gallery eg
update_field('field_6976a8648a5b', 'a:5:{i:0;i:4918;i:1;i:4916;i:2;i:4917;i:3;i:4915;i:4;i:4914;}', $post_id);but neither are working. Before I try some more debugging I wanted to check if I have the correct approach here, or if there is a different way of doing this?
Many thanks
You must be logged in to reply to this topic.