WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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'm migrating content from an existing site into wordpress. The old site has cross links that I'd like to maintain in the new site. I can convert the old links to wordpress format links (based on post-id), but in order to do that I need to assign the posts their own ID's on migration. is there any way to do that ?

The old site is NOT wordpress based...

share|improve this question
up vote 6 down vote accepted

Yes, use the "import_id" field in the post, when calling wp_insert_post.

This is treated as a "suggested" ID for the post that will be used if no post with that ID already exists.

$post = array(
share|improve this answer

Do you mean that old site used "ugly" permalinks? http://example.com/?p=N

I am not entirely sure about mechanics of import but in general case WordPress wp_insert_post() function does not allow to create posts with specific ID. Such input is treated as attempt to update existing post and fails (I assume from look at code, not tested) if post does not exists. See Otto's answer about import_id which I missed. Following still stands for cases when IDs are not numeric or otherwise can't be smoothly transferred to WP IDs.

My idea would be to map old ids to guid in WP, then run replacements for links in database.

share|improve this answer
the old site is not wordpress based. but it did use such links :-) – hannit cohen Jan 18 '11 at 13:26
@hannit cohen ah... I am way too sleepy and slow today to read question carefully. :( How are you going to migrate exactly? If you import old IDs/links as guid in WP then it will be easy to match them with new IDs. – Rarst Jan 18 '11 at 14:04
Hmm... cas\re to elaborate ? whats the difference between ids and guid ? I have the old DB and want to create every "article" from the old site as post on the new one. have manually created the categories (coz the structure has changed) and will assign posts to categories according to some match table. all I need is a way to maintain post internal links - only way to do that is to know the post id, or otherwise I'll have to lookup every "old" post in oreder to replace the link – hannit cohen Jan 18 '11 at 14:17
@hannit cohen guid is separate field in database, it isn't used in code like IDs but it is supposed to be unique identifier (WP mostly stuffs links in it). If you import your old IDs as guid then you can do something like - for every post replace in database link with guid by link with id. – Rarst Jan 18 '11 at 15:00

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.