Home Forums Backend Issues (wp-admin) Generate Media Description from Custom Fields


Generate Media Description from Custom Fields

  • NOTE: I have just opened a support ticket for this as well, but in order to get help from the community and the potential solution to be available to others as well, I’m essentially duplicating it in the forum as well.

    I have added a few custom text fields to media attachments using ACF. These include:

    – hqr_artwork_artist
    – hqr_artwork_medium
    – hqr_artwork_price

    Now what I need to do is that whenever an attachment is saved, the Description field (the one that comes built-in with WordPress for media items and is essentially the_content for the attachment post type) gets updated automatically to the following:

    Artist: <?php get_field( “hqr_artwork_artist” ) ?><br />
    Medium: <?php get_field( “hqr_artwork_medium” ) ?><br />
    Price: <?php get_field( “hqr_artwork_price” ) ?>

    So essentially, I need to take the values of these ACF fields and use them to create a custom content string for the Description field that I can then show in a lightbox in galleries, or use elsewhere in the theme (such as on the attachments template) using a single template tag.

    I don’t know which action to use for the purpose (and how to use it) so that this works immediately after a media item is saved, be it when adding a new item to the media library and specifying these custom fields for the first time, or when editing an existing item in the media library and changing the values of any of these custom fields.

    Any help in this regard (preferably as a working example) will be immensely appreciated.

  • You want to use the acf/save_post hook

    In the filter you create you need to get the values from your field and then use to update the description (the content) of the attachment post.

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

The topic ‘Generate Media Description from Custom Fields’ is closed to new replies.