WordPress.org

Forums

media_sideload_image generates blank? (2 posts)

  1. flxfxp
    Member
    Posted 3 years ago #

    I'm creating a custom post form that is supposed to take an external image and uploads it to the media library and attach it to that post. This should be possible by using media_sideload_image, but I'm getting a blank page instead of working correctly, no error either. My code:

    // Add the content of the form to $post as an array
            $new_post = array(
                'post_title'    => $title,
                'post_content'  => $description,
                'tags_input'    => $tags,
                'post_type'     => 'link_submit',
                'post_status'   => 'publish'
            );
            //save the new post and return its ID
            if ($stop == false){
                $pid = wp_insert_post($new_post);
                update_post_meta($pid,'Link',$link,true);
                update_post_meta($pid,'Type',$type,true);
                        // attach image
                set_time_limit(300);
                $upload = media_sideload_image($link, $pid, "test");
                if ( is_wp_error( $upload ) ){
                die( 'Nope' );
                }
    
                $link = get_permalink( $pid );
                wp_redirect( $link."?posted" );
                die();
            }

    Ideas?

    Thanks, Dennis

  2. ed4becky
    Member
    Posted 3 years ago #

    Did you get this working?

Topic Closed

This topic has been closed to new replies.

About this Topic