Set Uploaded Image Data by Field Value
Code
Filename: gpml-set-uploaded-images-data-by-field-value.php
<?php
/**
* Gravity Perks // Media Library // Set Uploaded Image Data by Field Value
* https://gravitywiz.com/documentation/gravity-forms-media-library/
*/
add_filter( 'gpml_media_data', function( $media, $field, $entry ) {
// Replace "1", "2", "3" and "4" in each line below with the ID of the field that will contain value that should be used for each image property.
$media['post_data']['post_title'] = rgpost( 'input_1' );
$media['post_data']['post_content'] = rgpost( 'input_2' );
$media['post_data']['post_excerpt'] = rgpost( 'input_3' );
$media['post_data']['post_meta']['_wp_attachment_image_alt'] = rgpost( 'input_4' );
return $media;
}, 10, 3 );
Thanks, when targeting a particular form it should look like this, right? https://gist.github.com/maskinmedia/6f874a7b71df53bace240b5ac20a1960
Hi Björn,
You can target a specific form by adding the form ID to the filter name:
add_filter( ‘gpml_media_data_FORMID’, ‘my_custom_function’ );
For for more info, please check out: https://gravitywiz.com/documentation/gpml_media_data/
Best,