WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have converted a site over to wordpress recently. I was able to import all the posts via a CSV importer, but not the images associated with each post. The post type is "machinery". The custom field with the post's previous ID on the old system of each post is called "machinery_legacy_idLocation". I have an additional table called "legacy_images".

"legacy_images" has 2 columns "ListingID" and "imageurl".

"ListingID" in the "legacy_images" table matches a post with the same "machinery_legacy_idLocation".

Now the "imageurl" matches the title of a corresponding image that I have already added to the media library in Wordpress.

Basically I just need to figure out a way to reattach all these images to all these posts after the move.

share|improve this question
This question is really "too localized" as you asking for a custom importer fitting your special needs. – kaiser Oct 5 '12 at 11:10
up vote 0 down vote accepted

wp_insert_attachment will insert an attachment post for a given parent post ID and filename. You can write a little script to query for all your posts with the legacy key, get their associated image paths, and call wp_insert_attachment for each.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.