Codex tools: Log in / create account
Contents |
This function inserts an attachment into the media library. The function should be used in conjunction with wp_update_attachment_metadata() and wp_generate_attachment_metadata(). Returns the ID of the entry created in the wp_posts table.
<?php wp_insert_attachment( $attachment, $filename, $parent_post_id ); ?>
To insert an attachment to a parent with a post ID of 37:
<?php $attach_id = wp_insert_attachment( $attachment, $filename, 37 ); $attach_data = wp_generate_attachment_metadata( $attach_id, $filename ); wp_update_attachment_metadata( $attach_id, $attach_data ); ?>
wp_get_attachment_url(), wp_delete_attachment(), wp_insert_post()