Skip to content

Instantly share code, notes, and snippets.

@spivurno
Last active July 17, 2020 08:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save spivurno/400fc922adbbd5a36184dcfab3be21e2 to your computer and use it in GitHub Desktop.
Save spivurno/400fc922adbbd5a36184dcfab3be21e2 to your computer and use it in GitHub Desktop.
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
Copy link

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