0

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?

Thanks

1

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 );
  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.