How can I assign post a specific ID on creation?

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…

2 Answers
2

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(
'post_title'=>'whatever',
'post_content'=>'whatever',
'import_id'=>123
);
wp_insert_post($post);

Leave a Comment