wp_insert_attachment ( $args, $file = false, $parent = 0, $wp_error = false, $fire_after_hooks = true )
- (string|array) args Arguments for inserting an attachment.
- (string|false) file Optional. Filename.
- (int) parent Optional. Parent post ID.
- (bool) wp_error Optional. Whether to return a WP_Error on failure. Default false.
- (bool) fire_after_hooks Optional. Whether to fire the after insert hooks. Default true.
Defined at:Change Log:
- (int|WP_Error) The attachment ID on success. The value 0 or WP_Error on failure.
- Introduced in WordPress: 2.0.0
- Deprecated in WordPress: —
Insert an attachment.If you set the 'ID' in the $args parameter, it will mean that you are
updating and attempt to update the attachment. You can also set the
attachment name or title by setting the key 'post_name' or 'post_title'.
You can set the dates for the attachment manually by setting the 'post_date'
and 'post_date_gmt' keys' values.
By default, the comments will use the default settings for whether the
comments are allowed. You can close them manually or keep them open by
setting the value for the 'comment_status' key.