WordPress Cor
An attachment ID is the unique numeric identifier WordPress assigns to every uploaded file. It is stored in the database as the post ID of the attachment record and used throughout WordPress — in blocks, custom fields, theme options and the REST API — to reference a specific file.
How attachment IDs work
When you upload a file, WordPress creates a database entry in wp_posts with an auto-incrementing ID. That number is the attachment ID. It never changes for the life of the file. If you delete the file and re-upload it, the new upload gets a new ID — there is no way to assign a specific ID to a new upload.
Attachment IDs appear throughout the codebase: in Gutenberg block attributes (
Why attachment IDs matter for governance
Because so many references use the numeric ID rather than the URL, deduplication is more complex than deleting the duplicate file. If 40 posts reference image ID 1234 and you delete it in favour of ID 5678 (the reference version), all 40 posts now have a broken reference. Mediapapa’s Safe Replace scans every ID reference across the database and updates them before the duplicate is removed.
Frequently asked questions
Can I find an attachment ID in the WordPress admin?
Yes. Open the Media Library, click any file to open its detail view, and look at the browser URL. The number after ?item= or post= is the attachment ID. You can also see it in the block editor when an image block is selected — the Block panel shows the numeric ID.
Does changing a file’s URL change its attachment ID?
No. The attachment ID is independent of the file URL. Renaming a file or moving it changes the URL, but the database record retains the same ID.
What happens to attachment ID references if I migrate my site?
Migration tools typically preserve attachment IDs by transferring the database intact. If IDs change during migration (for example, when merging two sites), all references in post content and custom fields need to be updated — a process that tools like Mediapapa’s Safe Replace can manage sitewide.
Related terms: Attachment · Safe Replace · Duplicate Images
Curious what is hiding in your library?
Scan it for free. No account needed.