<?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 );
I’ve tried you snippet with my form (Form ID 1) which has a File Upload field and the Upload to Media Library Perk enabled. I then have a basic text field setup for the image caption (field ID 20). This is part of a form that is using the GF Advanced Post Creation Add-on as well. When I submit the form, the image is in the Media Library, but the caption text entered in the field is not attached to image via Title, Description, Caption or Alt Text.
Here’s the code based off of your snippet, https://gist.github.com/codysnodgrass/87ef9df9865fe3272461a93c558d44f6
Here’s my form, https://beta.veteransvoices.org/archive-submissions/
Let me know if you need anything else.
Hey Cody,
We’re going to need to take a closer look at the current configuration to see what’s going on here. Please submit a ticket via our support form so we can take a closer look at your setup and help you further with this. 🙂
Cheers,
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,