wpseek.com
A WordPress-centric search engine for devs and theme authors
wp_insert_attachment › WordPress Function
Since2.0.0
Deprecatedn/a
› wp_insert_attachment ( $args, $file = false, $parent_post_id = 0, $wp_error = false, $fire_after_hooks = true )
Parameters: (5) |
|
See: | |
Returns: |
|
Defined at: |
|
Codex: | |
Change Log: |
|
Inserts 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.Related Functions: wp_insert_comment, wp_delete_attachment, wp_count_attachments, is_attachment, wp_get_attachment_url
Source
function wp_insert_attachment( $args, $file = false, $parent_post_id = 0, $wp_error = false, $fire_after_hooks = true ) { $defaults = array( 'file' => $file, 'post_parent' => 0, ); $data = wp_parse_args( $args, $defaults ); if ( ! empty( $parent_post_id ) ) { $data['post_parent'] = $parent_post_id; } $data['post_type'] = 'attachment'; return wp_insert_post( $data, $wp_error, $fire_after_hooks ); }