最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Is this the correct way to add post-slug input field?

programmeradmin10浏览0评论

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?

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 edited Dec 24, 2011 at 9:34 Jenny asked Dec 24, 2011 at 8:18 JennyJenny 1,7674 gold badges27 silver badges41 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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

发布评论

评论列表(0)

  1. 暂无评论