Support

Account

Home Forums Bug Reports Custom Attachment Fields

Solving

Custom Attachment Fields

  • I am using the attachment_fields_to_edit filter to add additional fields to the image detail box (seen when you click an image from the gallery field type).

    The fields are showing up as expected, however any changes to the fields are not properly saved to the post meta.

    Looking through the code for the gallery field, I see there is a function called “ajax_update_attachment” which specifically only looks for the hardcoded fields: title, caption, description, alt.

    This function needs to be updated to check the filter attachment_fields_to_save so that any user defined fields are updated properly.

  • I added the following code onto line #194 of /pro/fields/gallery.php

    $post = apply_filters( 'attachment_fields_to_save', $post, $changes );

    That seems to do the trick. Would be great to have this added into the next release of ACF

  • Any update on this?

    These custom attachment meta fields are being displayed properly (line #357 of /pro/fields/gallery.php)

    However without the fix I outlined above, changes to custom meta fields are never saved to the database.

    If ACF isn’t going to properly save the data from these fields, then they shouldn’t be displayed to begin with. But obviously the better solution is simply to call the ‘attachment_fields_to_save’ filter as I outlined above.

    I have this working on a project however until this fix gets included into ACF it will be overwritten with every new update.

  • I’m noticing the same issue.

    @mkeys – Thank you very much for the patch. The patch is nice to have, but like you would prefer an update to the plugin.

  • No problem, glad it helped you. Hopefully @elliot can incorporate it soon.

    Also, Tarheel huh? I am in Raleigh.

  • That’s pretty funny. I’m in Raleigh too!

  • It sounds like this may have been fixed in the latest update. From the changelog:

    Gallery field: Added attachment_fields_to_save filter for 3rd party custom field support

    I haven’t had a chance to test yet though.

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

You must be logged in to reply to this topic.