Home Forums Add-ons Gallery Field Gallery Fields not attaching images to custom post type


Gallery Fields not attaching images to custom post type

  • I have a custom post type in my wordpress install which I use to generate galleries. I use the Gallery addon to let the user select and rearrange the images.

    Once the user click the images they are taken to the single attachment page.

    When adding images to the post from the media library, using the gallery field, the images are not attached to the post, meaning that the permalinks are not formed correctly and I cannot use the wordpress built in next_image_link() feature for navigation.

    If I upload the images directly into the gallery then they are attached properly but if I select them from the media library then they do not attach.

    I’m not sure if this is a bug or the expected behaviour. I only discovered it because sometimes when uploading many images at once the upload glitches and does not add the images into the gallery.

    Many thanks

    Jamie Roberts

  • I do not think that the ACF galleryfield works in the same way as wordpress built in gallery function.. Meaning that when you create a ACF gallery you can not expect the same functionality as with an wp gallery.. however this gives you immensely more freedom to set up the gallery as you like it (with a custom lightbox or whatever)

  • I’m experiencing a similar issue. This is with the ACF plugin and the gallery add-on both fully updated.

    , it definitely does not work the same way as the built in gallery function, but consistency between two different ways of adding images to the gallery field is a reasonable expectation. Either the images should never be attached to the post regardless of how they’re added (not ideal, IMO), or they should always be attached (ideal, IMO).

  • Hey guys,

    Thanks for the bug report.

    I’ll do some testing and find out what’s going wrong.


  • I don’t have this issue at all.

    I have a premium WordPress plugin that creates a custom post type, images from wherever can be placed there, and published. Doesn’t matter if the images aren’t attached to the post. This is the main reason I started using ACF and the gallery add-on, was to free my users from this, as well as having to do a feckin regex to just to pull the ID”s to get a correct gallery order when fetching attachments.

  • Hi @nphaskins

    Sorry, but why have you posted this? I don’t understand why you have posted a comment to say you don’t have this issue…


  • Because if I’m not having the issue then it’s probably not a real bug. How does that NOT help you? lol

  • Hi @nphaskins

    Thanks for the clarification. Much appreciated

  • Hi Elliot,

    I am having the same problem as @[email protected] and @tnorthcutt

    Images attach when you upload them directly to the post but they don’t attach when you select them from the Media library.


  • Was there ever any resolution to this? I’m trying to track down an issue I seem to be having a possibly similar issue with ACF Form and using it from the front-end to add images to a post or post gallery.

    What’s working:
    I can create my form and use it with the uploader to add images to the media library which also get attached to the correct post (records created in wp_postmeta).

    What’s not working:
    When I look at the custom post type record in the admin the images are not associated with their ACF field. Looking in the database I can see there are no act records for the image or gallery fields in wp_postmeta

  • I could be wrong, but this is my understanding of things.

    When you’re in the admin on a post edit page and you click on “insert image” in the editor, or add images using an ACF field, these images are “attached” the current post that is being editor. WP has a post ID to associate the images with at the time they are inserted.

    If you select an image that is already attached to another post, this image does not get “attached” to the post you are editing. What post an image is “attached” to is set by the post_parent row in the database and a post (attachment) cannot have 2 parents.

    If you go to the media library and upload images, unattached images will be attached to the first post they are used on.

    When creating a new post in the admin, WP creates an “auto draft” of the new post and uses the id of this yet to be created post for attaching images.

    On a front end form if you are editing and existing post, in other words, the post ID used for acf_form() is the same as the post ID where the form is displayed, WP will also attach any image that are uploaded or added to the fields that are not already attached.

    In the case of adding a new post using an acf_form() there is no auto draft post created. When the images are uploaded WP does not know where to attach them to. It could be that they get attached to the post ID of the current post being shown or to nothing at all. I haven’t actually investigated this. There could be other cases, for example if your ACF form is shown on some type of archive page where there is not “post id”. It could be that the images are not attached anywhere, or possibly they are attached to the last post in the last loop. I also don’t know what happens when you’re editing a different post in ACF than the post where the form appears. All of these things will act in one way or another to confuse WP as to exactly where it should be attaching new images or adding images images that were not previously attached. The only thing that I am sure of is that if the image is already “attached” to another post.

    How can this be corrected?

    Add an update value filter to image and gallery fields. Check to the images to see if they are attached to the current post ID being saved. In order to keep with the way WP does things you should also make sure that they are not attached to another post. If they are not attached to something else then attach them to the current post by setting their post_parent value. But this will not help in the case where WP confuses where to attach them in the first place since it’s already attached them. In this case you would need to break from the way WP usually does things and always attach the image to the current post being edited.

    I don’t honestly see an acceptable way to correct this since WP does not keep any type of list anywhere telling you every location where an image is used and it does not have the ability to attach and image to more than one post….. unless I’m missing something.

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

The topic ‘Gallery Fields not attaching images to custom post type’ is closed to new replies.