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.

Warning: Cannot modify header information - headers already sent by...

  1. I'm getting the above message as an error every time I perform certain administrative actions in my WP dashboard (e.g. deleting a post, editing code in Appearance > Editor, etc.)

    It seems that this problem only arises when I add the following code to my functions.php:

    <?php
    
    add_filter("gform_post_submission_1", "gform_set_post_thumbnail");
    
    function gform_set_post_thumbnail($entry){
    
        // get post ID of the created post
    
        $post_id = $entry["post_id"];
    
        // get the last image added to the post
    
        $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
    
        // set image as the post thumbnail
    
        set_post_thumbnail($post_id, $attachments[0]->ID);
    
    }

    I require this code as its function is to set the image uploaded in my Gform to be the Featured Image of the user-submitted post.

    Would appreciate any help on this matter :)

    EDIT: Resolved this myself. I simply moved the code that I quoted above to the top of functions.php.

    Posted 10 years ago on Monday August 22, 2011 | Permalink

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