Source:
- WordPress site hosted on Pantheon (friend’s server)
- No FTP, SSH, or plugin installation access
- SSL certificate never installed by previous host. Inconceivable :P
Bottom line - don't even try without back-end access. sure web scraping can be an interesting challenge, but really it's not worth the effort to manually realign images that are not mapped by pathname. An SQL dump is the only way to do this right!
Files:
-
blogtopusblues.WordPress.2026-01-09.xml→ full site export -
blogtopusblues.WordPress.2026-01-09-media.xml→ media-only export -
Both placed in:
~/projects/octopus/
Extraction + Download Process:
- Extract image URLs from media XML:
grep -oP '(?<=<wp:attachment_url><!\[CDATA\[).+?(?=\]\]></wp:attachment_url>)' blogtopusblues.WordPress.2026-01-09-media.xml > urls.txt
- Create target download folder:
mkdir media cd media
- Download images with SSL check bypass:
xargs -n 1 curl -O --insecure < ../urls.txt
Result:
-
Media files downloaded to:
~/projects/octopus/media/ -
Safe workaround for expired SSL certificate using
--insecure
Ahh — got it now. Given:
- ❌ No access to the original database
-
✅ You do have:
-
The full
.xmlexport (with attachment metadata + post content) - All the image files correctly downloaded
- Media folder populated
- The destination WordPress ready
-
octopususer created
-
The full
You're in the best possible position under those constraints. And the good news is:
💡 A WordPress
.xmlimporter re-creates the essential Media Library + attachment IDs using just that.xml— it does not need the original database.
Let’s document what we’ve done so far, and how the .xml import failed, and then pivot logically toward using the database directly if that's now the clearer path.
🧾 Summary: How We Tried to Upload the XML
🔹 Goal
Reconstruct lost author attribution, featured image relationships, and media linkage in posts, using the file:
blogtopusblues.WordPress.2026-01-09.xml
This .xml contains:
-
post_type = "post"and"page" -
post_type = "attachment"entries -
Featured image references (
_thumbnail_id) - Author mappings
🔹 Process We Attempted
-
✅ Created user
octopus -
✅ Manually restored images to
/wp-content/uploads/(viacurl) - ✅ Images appeared in Media Library
-
🛠 Ran the importer via:
Tools → Import → WordPress -
Mapped authors →
octopus -
Checked:
[x] Download and import file attachments - Clicked Submit
🔴 Result: Import Did Not Succeed
-
Posts remained assigned to
admin - Featured images were not reconnected
- Media attachment IDs were not restored
-
Post content was not re-linked to
wp:imageblocks -
Error seen:
“Failed to import media” (harmless re: files, but fatal re: metadata)
🧠 Root Problem
The XML importer plugin relies on WordPress creating attachment posts in the database that map:
filename.jpg → post ID → parent postBut because:
- Files were already present
- And media entries already existed
- The importer skipped over or failed to reconcile these relationships
The result: no media → post links, no _thumbnail_id, and no author reassignment.
✅ Next Logical Step: Use the Database Directly
Since:
- You don’t have the original MySQL database from source
- But you do have the XML
- And the images are already present
You can now:
🛠 Reconstruct what the importer would’ve done — directly into the database.
🗂️ Outline of What the Database Strategy Would Do
1. Rebuild wp_posts rows for:
-
post_type = attachment -
With correct
guid,post_mime_type,post_title,post_parent - Manually link each image file to its original post
2. Reconnect _thumbnail_id via wp_postmeta
Each post that used a featured image needs:
INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
VALUES (POST_ID, '_thumbnail_id', ATTACHMENT_ID);3. Optionally, reassign post authors
UPDATE wp_posts SET post_author = OCTOPUS_ID WHERE post_author = ADMIN_ID;✅ Requirements
To proceed with this DB-based rebuild, we’ll need:
-
The current
wp_poststable structure -
A reliable export of the relevant parts of the
.xmlfile (can parse it to extractattachment_url, titles, post ID mappings) -
Access to phpMyAdmin, or CLI access to
mysql
🚧 Do You Want to Proceed With:
-
Extracting structured post + media data from the
.xml -
Generating
INSERTstatements to rebuild what the importer failed to do
Or pause and reassess?
If you're ready, I can help extract key rows from the XML and write the SQL stubs to begin repairing the database directly.
Is there an easier way???
🟢 Summary of Where You're At
- ✅ Your Media Library is full of images again (good!)
- ✅ Auto Featured Image did its job
-
🧠 The post list UI still says
Image (PRO)— but you can ignore that for now - ✅ You now have access to the WYSIWYG editor and can insert images manually (that was blocked earlier)
- ⚠️ You accidentally re-imported menu items — again 😅
✅ Tonight's Goal: Insert a Few Images
Here’s how to manually insert images into posts/pages now:
- Go to Posts → All Posts (or Pages)
- Click Edit on one you want
- Inside the editor, click the plus (+) icon or use the block menu
- Choose Image
- Click Media Library, pick your image
- Set alignment / alt text if you like
- ✅ Done
This now works because the images are actually in the Media Library, so the block editor can see them.
You're totally fine — this was a productive start, and you’re closer than it might feel. Here's a quick, clear summary for when you revisit with Cdex or want to hand it off.
✅ Goal
Automatically link already-uploaded Media Library images to the posts that reference them.
💡 What You Already Have
-
Media files are correctly uploaded (
wp-content/uploads/YYYY/MM/filename.jpg) - Media Library entries exist with metadata
-
Post content (in
wp_posts) contains references to those filenames (e.g.,Stephen_Stohn_2022.jpg) -
But attachments are “Unattached” —
post_parent = 0
🛠️ What Needs To Happen
Link each image to the post that mentions it in the body.
This means updating the post_parent field in the wp_posts table for each image (attachments are stored in the same table).
🔧 Two Options to Automate This
1. PHP Snippet (Safe + WordPress-native)
Use this in a custom plugin or functions.php in your theme:
function bulk_attach_images_to_posts() {
$attachments = get_posts([
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_status' => 'inherit',
]);
foreach ($attachments as $attachment) {
$filename = basename($attachment->guid);
$matching_post = get_posts([
's' => $filename,
'post_type' => 'post',
'post_status' => 'publish',
'numberposts' => 1,
]);
if (!empty($matching_post)) {
wp_update_post([
'ID' => $attachment->ID,
'post_parent' => $matching_post[0]->ID,
]);
}
}
}
Call this once (e.g., on an admin page or via CLI), then remove it.
✅ Pros: Works with WordPress safely, updates all images that match
❌ Cons: Requires adding PHP to theme/plugin, a little setup
2. SQL Version (Database-level)
Run in phpMyAdmin or via wp-cli db query if you prefer direct SQL:
UPDATE wp_posts a
JOIN wp_posts p
ON p.post_type = 'post'
AND p.post_status = 'publish'
AND p.post_content LIKE CONCAT('%', SUBSTRING_INDEX(a.guid, '/', -1), '%')
SET a.post_parent = p.ID
WHERE a.post_type = 'attachment';
✅ Pros: Fast, no code
❌ Cons: Not WordPress API-safe (could miss hooks)
❓ Which is better: Plugin or Theme Function?
Option
When to use it
Theme function
Quick test on a staging site, discard after use
Plugin
Better for safety, reuse, or sharing with Cdex/Lisa
📌 Recommendation for Cdex
- Start with the PHP snippet (above)
- Create a simple one-time custom plugin (can send you a zip if needed)
- Click a button, update all attachments
- Then delete or disable the plugin when done
Let me know whenever you're ready to continue — this can be solved quickly now that the pieces are lined up.