Forum Replies Created

Viewing 1 replies (of 1 total)
  • I am very new to WordPress but I expect you can find what you want by following through what media_handle_upload() does in “wp-admin/includes/media.php”.

    Ultimately, you have to do the following to create the attachment:

    // Save the data
    	$id = wp_insert_attachment($attachment, $file, $post_id);
    	if ( !is_wp_error($id) ) {
    		wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
    	}

    Setting up the attachment array looks relatively straight forward since it is pulling mostly out the $_POST array which in your case would be replaced with the known values for the preset file you want to attach.

    Cheers

Viewing 1 replies (of 1 total)