how can I choose post ID, when inserting new post, ex:
$post = array(
'ID' => 3333,
'comment_status' => 'open',
'post_content' => 'hi world!',
'post_name' => 'title_1',
'post_status' => 'publish',
'post_title' => 'sdfsfd fdsfds ds',
'post_type' => 'post',
);
$post_id = wp_insert_post($post);
want to insert new post with id = 3333
Thought you might like to know you can use
'import_id'
instead of'ID'
and it will "try" and use that.See the second example here: http://codex.wordpress.org/Function_Reference/wp_insert_post#Example
It is possible to do this, just not with the API's insert function. You can write your own INSERT query instead. You always want to use the API when you can, but sometimes it's not possible. The query would look like this:
You'll have to make sure that the ID doesn't already exist in the database first. If the post table schema changes in the future you may need to update the query to account for the changes.
Here is my simple solution:
'ID'=> post_id will update that post, while 'import_id'=> post_id will create a new post with that id.
You can also loop through and feed the IDs to run multiple insertions/updates without the risk of creating an infinite amount of new posts.
Sorry buddy, not doable. Here is what the devs say at the codex:
http://codex.wordpress.org/Function_Reference/wp_insert_post
As daveaspinall say. I do a function that do that.
example: