How can I assign post a specific ID on creation?

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