Title: Fixed: Creating a gallery programatically
Last modified: March 22, 2026

---

# Fixed: Creating a gallery programatically

 *  Resolved [jamesinealing](https://wordpress.org/support/users/jamesinealing/)
 * (@jamesinealing)
 * [2 months, 2 weeks ago](https://wordpress.org/support/topic/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)
 *     ```wp-block-code
       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
    -  This topic was modified 2 months, 2 weeks ago by [jamesinealing](https://wordpress.org/support/users/jamesinealing/).

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fcreating-a-gallery-programatically%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/acf-galerie-4/assets/icon-128x128.jpg?rev=3337758)
 * [ACF Galerie 4](https://wordpress.org/plugins/acf-galerie-4/)
 * [Support Threads](https://wordpress.org/support/plugin/acf-galerie-4/)
 * [Active Topics](https://wordpress.org/support/plugin/acf-galerie-4/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/acf-galerie-4/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/acf-galerie-4/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [jamesinealing](https://wordpress.org/support/users/jamesinealing/)
 * Last activity: [2 months, 2 weeks ago](https://wordpress.org/support/topic/creating-a-gallery-programatically/)
 * Status: resolved