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.

Add the Featured Image of a Post to a Gravity Form on that page

  1. Hi GF

    I am looking for solution to allow a gravity form to dynamically pull in the featured image of a post the same way it can pull in the post title.

    Basically this is a form on a products website. On the product details page is a modal with an enquiry form in it (a gravity form). I need it that when the user opens the modal with the form, two fields need to populate automatically - the post title and the featured image. We have the post title working, but cannot get the image to display.

    We tried something like this:

    add_filter('gform_field_value_prodimage', 'populate_post_prodimage');
    function populate_post_prodimage($value){
        global $post;
    
        $prodimg = set_post_thumbnail($entry['post_id']);
    
        return $prodimg;
    }

    But it doesn't appear to be working.

    Any suggestion?

    Posted 7 years ago on Sunday March 10, 2013 | Permalink
  2. Why are you using 'set_post_thumbail' here, if you are trying to retrieve what is saved as the featured image? How about get_the_post_thumbnail http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail

    Posted 7 years ago on Wednesday March 13, 2013 | Permalink
  3. OK i have change the code to the get_the_post_thumbnail but now how do i pull that into an image field / checkbox on the form?

    Posted 7 years ago on Sunday May 12, 2013 | Permalink
  4. In case anyone else trying to find a solution, i finally managed to hack this solution:

    add_filter('gform_field_choices', 'update_choices', 10, 2);
    function update_choices($choice_html, $field){

    if($field['formId'] != 3)
    return $choice_html;

    if($field['id'] == 21) {
    // in this example, "First Choice" is one of the option labels, we replace that with the image
    // the reason we include the "><" when searching for the "First Choice" text is because unless
    // the 'enable values' option is selected for this field, it would replace both the value and
    // the label, we just want to update the label

    global $post;
    $feat1 = '<img src="';
    $feat2 = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    $feat3 = '" width="250" height="220" />';
    $featimage = $feat1 . $feat2 . $feat3;
    return $featimage;
    }

    Posted 7 years ago on Sunday May 19, 2013 | Permalink