EDIT (July 2011)
PLEASE NOTE: This code is out of date and no longer works.
Please see this post instead:
http://www.gravityhelp.com/forums/topic/fatal-error-when-using-the_post_thumbnail-code-snippet#post-30918
I like your idea about having some sort of collaboration on these code snippets. Could work really well.
Try the following code snippet to set your post thumbnails
Ignore the code below
add_filter("gform_post_submission", "set_post_thumbnail", 10, 2);
function set_post_thumbnail($entry, $form){
//Replace 4 with your actual form id
if($form["id"] != 4)
return;
//getting first image associated with the post
$post_id = $entry["post_id"];
$attachments = get_posts(array('numberposts' => '1', 'post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC'));
if(sizeof($attachments) == 0)
return; //no images attached to the post
//setting first image as the thumbnail for this post
update_post_meta( $post_id, '_thumbnail_id', $attachments[0]->ID);
}
EDIT (July 2011)
See this post for an updated solution:
http://www.gravityhelp.com/forums/topic/fatal-error-when-using-the_post_thumbnail-code-snippet#post-30918
Posted 14 years ago on Tuesday May 11, 2010 |
Permalink