PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Set an uploaded image as the Featured Image?

  1. guildmeister
    Member

    Is there a way to automatically set an uploaded image as the Featured Image? I found some code to place the image as a thumbnail, so that solves half my problem. But I'd like it to be the featured image as well.

    Thanks in advance!
    Donna

    Posted 14 years ago on Wednesday November 17, 2010 | Permalink
  2. Currently there is no built in way to set the image uploaded as the feature image. It is a feature we plan on looking into how we can implement in a future release. It would be possible to do now but would require a customization and WordPress development knowledge to do so.

    Posted 14 years ago on Wednesday November 17, 2010 | Permalink
  3. blrfurther
    Member

    @guildmaster here is what I am using (please correct me if this is not the best practice)

    add_action("gform_post_submission", "post_submission_handler");
    function post_submission_handler($entry){
        global $wpdb;
    
        $results = $wpdb->get_results($wpdb->prepare("  SELECT l.*, field_number, value
                                FROM wp_rg_lead l
                                INNER JOIN wp_rg_lead_detail ld ON l.id = ld.lead_id
                                WHERE l.id=%d
                                ORDER BY  l.id, field_number", $entry["id"]));
    
        foreach($results as $result){
           	$post = $result->post_id;
           	$images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent='.$post );
    		if ( empty($images) ) {
    			// no attachments here
    		} else {
    			foreach ( $images as $image ) {
    				$featured =& add_post_meta($post, '_thumbnail_id', $image->ID );
    				break;
    			}
    		}
    
    	}
    }
    Posted 14 years ago on Wednesday November 17, 2010 | Permalink
  4. guildmeister
    Member

    Thank you both!

    blrfurther do you use that code in the post template?

    Posted 14 years ago on Friday November 19, 2010 | Permalink
  5. @ guildmeister - Can you please point me to the code that you found to add the image as a thumbnail? Thanks!

    Posted 14 years ago on Saturday November 20, 2010 | Permalink
  6. guildmeister
    Member

    @Kirsten Sorry for the delay in replying I've not been getting notifications of updates to the posts. Here is the code I used in a Post Fields Body widget. Under the Properties of that widget you make sure the Create Post Content Template box is checked. The first thing I have in the field that will create the post content is this:

    {Main Image:4:thumbnail:left}{Description:3}

    The numbers may be different for your form. This code will put the image as a thumbnail, left-aligned with the body text (I called my body widget Description) wrapped around it.

    I hope that helps.

    Posted 13 years ago on Tuesday February 15, 2011 | Permalink
  7. jcollier
    Member

    Doesn't work with WP 3.2. Go here for the fix:

    http://www.gravityhelp.com/forums/topic/support-post-thumbnails

    Posted 13 years ago on Wednesday July 20, 2011 | Permalink

This topic has been resolved and has been closed to new replies.