Last active
July 17, 2020 08:12
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
</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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.