Hi thanks for the feedback.
You will have to make use of one of my plugin’s action hooks to do this.
add_action( ‘prso_gform_pluploader_processed_uploads’, ‘You_Function’ );
function Your_Function( $wp_attachment_data, $entry, $form ) {
// $wp_attachment_data will contain all info on the uploaded file
// $entry and $form contain data from gravity forms e.g you should find the post id in $entry[‘post_id’]
// You will then have to update post meta value ‘_thumbnail_id’ to match the attachment id for your new post, you should find the attachment id in $wp_attachment_data array
}
Hope this helps
Hey, I need the same, but my users should be able to upload up to 5 files.
I want to choosethe first as featured image, but I’m not an expert and I don’t know how to customize and where to put the code above.
If there is a way to do that, is there also a way to set it for all forms, not just for a specific ID?
I would be happy if you could help me out.
Thanks in advance.
P.S. Thanks for the latest update, it does not kill the WP Uploader anymore 🙂
Hi
What you ask is a little advanced but not a problem if you are comfortable with wordpress action hooks.
Put this in your themes functions.php file and it should trigger every time a file is processed by the plugin and gravity forms creates a new post with the form data:
add_action( ‘prso_gform_pluploader_processed_uploads’, ‘prso_adv_upload_featured_image’, 10, 3 );
function prso_adv_upload_featured_image( $wp_attachment_data, $entry, $form ) {
//Init vars
$post_id = NULL;
$post_attachment_id = NULL;
//Check that gravity forms created a new post
if( isset($entry[‘post_id’]) ) {
//Cache post id from gravity forms
$post_id = $entry[‘post_id’];
//Get first uploaded attachment id
$post_attachment_id = current( $wp_attachment_data )[0];
//Update post thumbnail id meta with first uploaded file
update_post_meta($post_id, ‘_thumbnail_id’, $post_attachment_id);
}
}
Thanks
Ben
Great, thank you very, very much.
No my new question is: Is it possible to add the other images as a gallery in the post?
Thanks
Found a really simple solution. Sorry for asking.
Just add [gallery] to the form.