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 added slug input field in my custom post type and allow users to edit it at front end. Then, when insert post, I use this:

$wp_insert_post_args = array(
            'post_status'   => 'publish',
            'post_type' => MY_POST_TYPE,
            'post_author'   => $this->creator_id,
            'post_title'    => $this->name
            'post_name'     => sanitize_title( $this->slug ) 

My custom post type already suports 'title', so, it suppose to auto generate post_name. Now I add $slug as 'post_name' as described above, will woredpress use 'title' to generate 'post_name', or use my 'slug'? will wordpress perform slug exist checking as it does on normal posts, or should I take care of the checking myself?

share|improve this question
up vote 0 down vote accepted

If the slug exsit WordPress will add a number to the end. For example if you had two post named "test" you would get "test" and "test-1"

Hope that helps

share|improve this answer
so, I don't need to perform a check? Also no need to apply some safty filter? – Jenny Dec 24 '11 at 9:19
Nope, WP has your back. You might want to perform a check if the numbers at the end bug you. – BandonRandon Dec 24 '11 at 20:36
Thanks, I will try it out. still not sure if wordpress will use 'title' or my slug input to generate the post name, but a test will tell. – Jenny Dec 25 '11 at 0:44

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.