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 building a membership based website that will use custom post types to store data. I came across a problem which is if two users happen to create a post using the same exact name, WordPress would add -2, to one of the users posts. I'd like to keep permalinks on and have a unique ID added to the end of the permalink so that the URL's appear as example.com/postname-XXX, where XXX is a unique ID.

I thought about using the post ID, but if a user is submitting from a form which is creating the custom post types am I able to insert the post ID before the post or permalink are set and if so how?

If this isn't possible what is another method to add a unique ID to the permalink from the form?


share|improve this question

I think you use the function wp_insert_post() from the form to create the post; the function return the ID and you can use it.

    if ( defined( 'WP_DEBUG' ) && WP_DEBUG )
        $wp_error = TRUE;
    // insert post
    $post_id = wp_insert_post( $new_postarr, $wp_error );
share|improve this answer
How does this add an ID (a number) to the end of the post name or permalink? – Anagio Dec 22 '12 at 11:03
The permalink have on default a key for this, create the permalink rules in settings and ready. – bueltge Dec 22 '12 at 12:34

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.