function update_attached_file( $attachment_id, $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.


  • int $attachment_id: Attachment ID
  • string $file: File path for the attachment

Return values

returns:False on failure, true on success.

Defined filters

  • update_attached_file
    apply_filters( 'update_attached_file', $file, $attachment_id )

Source code

function update_attached_file( $attachment_id, $file ) {

	if ( !get_post( $attachment_id ) )

		return false;

	$file = apply_filters( 'update_attached_file', $file, $attachment_id );

	$file = _wp_relative_upload_path($file);

	return update_post_meta( $attachment_id, '_wp_attached_file', $file );



No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: