Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gravity Perks // GP Media Library // Auto-attach Uploaded Files to GF-generated Post
</php
/**
* Gravity Perks // GP Media Library // Auto-attach Uploaded Files to GF-generated Post
* http://gravitywiz.com/documentation/gp-media-library/
*/
add_action( 'gform_after_create_post', function( $post_id, $entry, $form ) {
if( is_callable( 'gp_media_library' ) ) {
$file_ids = gp_media_library()->get_file_ids_by_entry( $entry, $form );
if( $file_ids ) {
foreach( $file_ids as $field_id => $_file_ids ) {
foreach( $_file_ids as $file_id ) {
wp_update_post( array(
'ID' => $file_id,
'post_parent' => $post_id
) );
}
}
}
}
}, 10, 3 );
@chriswagoner

This comment has been minimized.

Copy link

chriswagoner commented May 19, 2017

David, what am I missing here? This isn't working for me. I added it to the functions.php of my child theme but it still doesn't attach to the page. I am using your Gravity Forms Media Library Perk, which works great. Still not seeing it as attached to the post.

Found this via: http://stackoverflow.com/questions/43472404/gravity-forms-uploading-files-as-post-attachments

Thanks.

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.