开发者

How to Set POST permalink/slug in wordpress using wp_insert_post

开发者 https://www.devze.com 2023-03-03 06:35 出处:网络
I m writing simple script using wp_insert_post() to post article in blog. but one problem here, I want to make Title and slug of an URL different.

I m writing simple script using wp_insert_post() to post article in blog. but one problem here, I want to make Title and slug of an URL different.

How to achieve this?

for example:

Title: How to make your diet success

Slug: 7-ways-to-make-succes开发者_C百科-Diet


post_title sets the title, and post_name sets the slug. So:

// Create post object
$my_post = array(
     'post_title' => 'How to make your diet success',
     'post_name' => '7-ways-to-make-succes-Diet',
     'post_content' => 'my content',
     'post_status' => 'publish',
     'post_author' => 1,
     'post_category' => array(8,39)
  );

// Insert the post into the database
wp_insert_post( $my_post );
0

精彩评论

暂无评论...
验证码 换一张
取 消