Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
map gravity form post image to a pods field
/*--------------------------------------------------------------
# Gravity forms does not let you map a post image field in a custom field
# If you use pods and you would like to be able to map a post image to a pods image field make sure:
# the post image is not featured as that would become the post thumbnail
# add a css class tot he post image field in the form of of field_pod_field_name ( must start with field_ )
--------------------------------------------------------------*/
add_action( 'gform_after_submission', 'add_pod_images', 10, 2 );
function add_pod_images( $entry, $form ) {
//it is being saved to a post
if(isset($entry['post_id']) ){
$post_id = $entry['post_id'];
foreach($form['fields'] as $field){
//if its a post image type and is not being saved as featured
if($field['type'] == 'post_image' && $field['postFeaturedImage'] == '' && strpos($field['cssClass'], 'field_') !== false){
$entry_id = $field['id'];
if( $entry[$entry_id] != ''){
//getting the last digits which are the media_id from entry value
preg_match('/[0-9]*$/', $entry[$entry_id], $value);
echo $field['cssClass'];
//css class must start with field_ this way you can still have other css classes
preg_match('/field_(\w*)/', $field['cssClass'], $custom_field);
update_post_meta($post_id, $custom_field[1], $value[0]);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.