Core Function
View Source on Trac ↗ wp_insert_attachment()
wp_insert_attachment(
mixed $args,
mixed $file = false,
mixed $parent_post_id = 0,
mixed $wp_error = false,
mixed $fire_after_hooks = true
) Inserts an attachment.
Parameters 2 required
| Name / Type | Description |
|---|---|
| (string | | array) $args Arguments for inserting an attachment. Required |
| (string | | false) $file Optional. Filename. Default false. Required |
| $parent_post_id int | Optional. Parent post ID or 0 for no parent. Default 0. |
| $wp_error bool | Optional. Whether to return a WP_Error on failure. Default false. |
| $fire_after_hooks bool | Optional. Whether to fire the after insert hooks. Default true. |
Return Value
((int)
| WP_Error) The attachment ID on success. The value 0 or WP_Error on failure.
Function Information
Since Version
2.0.0
Source File
wp-includes/post.php
Advertisement