Add image custom attribute [closed]

You need to use the hooks attachment fields to edit / save to ad and save the fields.

function add_attachment_field_credit( $form_fields, $post ) {
    $form_fields['paper-type'] = array(
        'label' => 'Paper type',
        'input' => 'text',
        'value' => get_post_meta( $post->ID, 'paper_type', true ),
        'helps' => 'Photo paper type'
    );
    return $form_fields;
}
add_filter( 'attachment_fields_to_edit', 'add_attachment_field_credit', 10, 2 );

function add_attachment_field_credit_save( $post, $attachment ) {
    if( isset( $attachment['paper-type'] ) )
    update_post_meta( $post['ID'], 'paper_type', $attachment['paper-type'] );

    return $post;
}
add_filter( 'attachment_fields_to_save', 'add_attachment_field_credit_save', 10, 2 );

So this has 2 functions, one adds the field as an array and returns it with the rest, and the second is run on save, checks for the fields and saves the data.

So that will handle getting the data into WordPress. I’m not sure about ACF, You’ll need to loop through the gallery and get each image, you should then be able to get the custom fields the same way you got the url and alt from the gallery.

If that doesn’t work you cna use get_post_meta with the attachment ID returned from the gallery to get the custom fields you set.