update_attached_file()
Update attachment file path based on attachment ID.
Used to update the file path of the attachment, which uses post meta name _wp_attached_file to store the path of the attachment.
Hooks from the function
Returns
Int|true|false
. Meta ID if the _wp_attached_file key didn't exist for the attachment. True on successful update, false on failure or if the $file value passed to the function is the same as the one that is already in the database.
Usage
update_attached_file( $attachment_id, $file );
- $attachment_id(int) (required)
- Attachment ID.
- $file(string) (required)
- File path for the attachment.
Examples
#1 Example of work
Suppose we added a new file and we need to update the path to this file, which is stored in the meta field _wp_attached_file
.
update_attached_file( $post_ID, $postarr['file'] );
Changelog
Since 2.1.0 | Introduced. |