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 am using a script to import my vbulletin forum posts into wordpress as posts.

One quick issue I ran into is there are numerous forum posts with the same title 'please help me'.

When I go into the post edit screen the permalink will show 'please-help-me-2' for the second one, and 'please-help-me-3' for the third one. That is exactly what I expect.

However, when you go to view the second one on the front end of the website, instead of having the -2 appended to the end of the url, it simply says 'please-help-me'.

If I 'update' the post, then the permalink saves properly and the front end link changes like it should.

What I need:

Is there a function that I can use to go through the posts database and have it automatically 'update' all the posts so that the permalinks will change properly on the front end?

*we're talking 1.25million posts here, so automation is important.


share|improve this question
Is wp_update_post() not the function you need? It will take a post array and update the existing post with the changed data. Although it really sounds like you need to alter your importer script to work better, frankly. – Otto Aug 21 '11 at 17:25
thanks Otto, exactly what I was after. You are correct, importer should rather be modified to do this right the first time instead of after the fact – shawn Aug 21 '11 at 22:37
up vote 0 down vote accepted

There is a function called wp_insert_post that takes a parameter for post ID. If the post ID is an ID that already exists, this function will update the post with the information you pass in the function parameters. I think using that function you could find a way to retrieve all of your post ID's in an array and then use a foreach loop to update each one.

share|improve this answer
You'll need to be really careful to retrieve your old post data and pass it into the parameters with your edits, though... I'd do this within a smaller scope for testing first, before risking your entire post database. – Chiubaka Aug 21 '11 at 22:28
thanks for the concept. I think that as Otto said, I need to rework the importer and try it again. – shawn Aug 21 '11 at 22:37

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.